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