Article View: comp.std.c
Article #134Re: Function Prototypes: Don't they force casts?
From: D'Arcy J.M. Cain
Date: Tue, 28 Jul 1992 11:19
Date: Tue, 28 Jul 1992 11:19
35 lines
1834 bytes
1834 bytes
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 |
Technical Details
Message-ID:
<1992Jul28.111916.4944@druid.uucp>Path:
arc1-ca.pugleaf.net!sparky!uunet!uunet.ca!geac!r-node!druid!darcyReferences:
<OINK.92Jul26032212@julian.newshost.uwo.ca>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c Path: arc1-ca.pugleaf.net!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