home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / std / c / 2371 < prev    next >
Encoding:
Text File  |  1992-07-28  |  1.7 KB  |  46 lines

  1. Newsgroups: comp.std.c
  2. Path: sparky!uunet!uunet.ca!geac!r-node!druid!darcy
  3. From: darcy@druid.uucp (D'Arcy J.M. Cain)
  4. Subject: Re: Function Prototypes: Don't they force casts?
  5. Message-ID: <1992Jul28.111916.4944@druid.uucp>
  6. Date: Tue, 28 Jul 1992 11:19:16 GMT
  7. References: <OINK.92Jul26032212@julian.newshost.uwo.ca>
  8. Organization: D'Arcy Cain Consulting
  9. Lines: 35
  10.  
  11. oink@newshost.uwo.ca (Test Account) writes:
  12. >#include <signal.h>
  13. > ... void memory_fault(void); */
  14. >[...]
  15. >    if ((int) signal(SIGSEGV, memory_fault) < 0) {
  16.  
  17. Prototypes don't actually cast.  Here is the relevant section:
  18.  
  19.     On entry to the function the value of each argument expression shall
  20.     be converted to the type of its corresponding parameter, as if by
  21.     assignment to the parameter.
  22.  
  23. So it isn't casting that is being done but rather promotion.  In this case
  24. you need the cast because the second parameter to signal isn't the same as
  25. your memory_fault function.  Signal handlers take an int argument.  The
  26. right way to fix this is fix your signal handler and declare it as:
  27.  
  28.     void memory_fault(int);
  29.  
  30. You are free to ignore the argument in the actual handler but you should
  31. still declare it in the parameter list.
  32.  
  33. >idea). This occurs IFF memory_fault() is declared AFTER its use or in another
  34. >module, if it is declared before its use there is no diagnostic. The fix is
  35.  
  36. This suggests that the handler actually is defined with an int argument
  37. except that you should get a diagnostic from the compiler if the above
  38. prototype is in scope when you define it.  Perhaps you don't have enough
  39. warnings turned on.
  40.  
  41. -- 
  42. D'Arcy J.M. Cain (darcy@druid.com)  |
  43. D'Arcy Cain Consulting              |   There's no government
  44. Toronto, Ontario, Canada            |   like no government!
  45. +1 416 424 2871          DoD#0082   |
  46.