Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!think.com!hsdndev!spdcc!dirtydog!karl From: karl@ima.isc.com (Karl Heuer) Newsgroups: comp.std.c Subject: Re: proper semi-portable use of signal()? Message-ID: <1991Mar27.194829.20212@ima.isc.com> Date: 27 Mar 91 19:48:29 GMT References: <3223@charon.cwi.nl> Sender: usenet@ima.isc.com Reply-To: karl@ima.isc.com (Karl Heuer) Organization: Interactive Systems, Cambridge, MA 02138-5302 Lines: 90 In article <3223@charon.cwi.nl> guido@cwi.nl (Guido van Rossum) writes: >Is the header wrong, is gcc overly worried, or is my code wrong? All of the above. The header is wrong, because the Standard specifies that signal handlers take a single arg of type |int|; the BSDism of pretending they're variadic is not compatible with existing practice. (Recommended fix: make your own copy of that adheres to the standard. See enclosure.) GCC is overly worried, but it did restrict it to a warning (rather than a fatal error), which is appropriate behavior for a compiler when presented with improper but fixable code. Your code is wrong because it uses the obsolescent |void (*sigsave)()| rather than the prototype |void (*sigsave)(int)|. This should not cause any problems, though, unless you're using the -Wstrict-prototypes option. Karl W. Z. Heuer (karl@ima.isc.com or uunet!ima!karl), The Walking Lint --------cut here-------- /* * Karl Heuer, 27-Mar-1991. Public Domain. * * For systems whose native is not ANSI-compatible. Imports most * stuff from the native , which we assume to be in /usr/include * (but we spell it with a double slash because some compilers warn about * including from /usr/include explicitly). The second paragraph can begin * with either an include of , which is expected to define * appropriate symbols in the _[SMCX]_* namespace, or the defines can be * inlined at this point. */ #if !defined(_H_SIGNAL) /* some implementations misdeclare signal() */ #define signal __dummy_signal #define sigvec __dummy_sigvec #include "/usr//include/signal.h" #undef signal #undef sigvec #define _H_SIGNAL #include #if defined(_S_UNIX_BSD) || defined(_X_HAS_SIGVEC) struct sigvec { #if defined(__STDC__) void (*sv_handler)(int); #else void (*sv_handler)(); #endif int sv_mask; int sv_flags; }; #if defined(__STDC__) extern int sigvec(int, struct sigvec const *, struct sigvec *); #else extern int sigvec(); #endif #endif /* BSD mutation */ #undef SIG_DFL #undef SIG_IGN #undef SIG_ERR #if defined(__STDC__) #if defined(lint) #define SIG_DFL ((void (*)(int))0) #define SIG_IGN ((void (*)(int))0) #define SIG_ERR ((void (*)(int))0) #else #define SIG_DFL ((void (*)(int))0) #define SIG_IGN ((void (*)(int))1) #define SIG_ERR ((void (*)(int))-1) #endif extern void (*signal(int, void (*)(int)))(int); extern int raise(int); #else #if defined(lint) #define SIG_DFL ((void (*)())0) #define SIG_IGN ((void (*)())0) #define SIG_ERR ((void (*)())0) #else #define SIG_DFL ((void (*)())0) #define SIG_IGN ((void (*)())1) #define SIG_ERR ((void (*)())-1) #endif extern void (*signal())(); extern int raise(); #endif #if !defined(SIGABRT) #define SIGABRT SIGIOT #endif #endif /* include guard */