Stanley S said:
Are Signal Handling part of ANSI C?
Yes, but not in a very flexible way. <signal.h> declares:
- sig_atomic_t, which is a type definition for use in signal functions
(and which is, basically, the only type that _can_ be used safely in
signal functions);
- the macros SIG_DFL, SIG_ERR and SIG_IGN, which can be passed to
signal() to designate default signal handling, an error during the
execution of signal() itself, and no signal handling;
- SIGABRT, SIGFPE, SIGILL, SIGINT, SIGSEGV and SIGTERM, which represent
the only signals ISO C recognises;
- signal(), which can be used to set the signal handler (and retrieve
the current one) for a specific signal; and
- raise(), which raises a signal.
Note that signal functions you write yourself are strongly restricted in
what they can do without causing undefined behaviour. You cannot refer
to any static object except by flagging a volatile sig_atomic_t (and you
can't access previously allocated objects, either, since you will have
no way to get at them except through a static object...); and you can't
call any Standard library function except abort(), _Exit(), or signal()
on the signal which was raised.
So basically, ISO C signals can set a (or several) flags. That _can_ be
turned into something useful, but it requires some work.
I am not able to find any reference of Sig Handling in Stephen Prata's
"C Primer Plus".
I wouldn't necessarily expect a Primer to cover signal handling. It is a
hairy business.
The usage of signals is to trap errors I guess.
Amongst others.
I gather POSIX signals are more powerful, but ask in
comp.unix.programmer for POSIX.
Richard