__attribute__((cleanup(function)) versus try/finally
Fergus Henderson
fjh@cs.mu.OZ.AU
Fri May 9 12:08:00 GMT 2003
On 09-May-2003, Andrew Haley <aph@redhat.com> wrote:
> Actually, the C standard is quite explicit about this: signal handlers
> may return either by a return statement of calling longjmp().
[I think you meant to say "or" instead of "of".]
What you say is true to some extent, but it only applies to signal
handlers for synchronous signals, i.e. those caused by an explicit
call to abort() or raise(). For asynchronous signals, the behaviour
is undefined if the signal handler calls longjmp(), due to
C99 7.14.1.1 paragraph 5, which prohibits such signal handlers
from calling *any* standard library function other than abort(),
_Exit(), or signal():
| If the signal occurs other than as the result of
| calling the abort or raise function, the behavior is
| undefined if the signal handler refers to any object with
| static storage duration other than by assigning a value to
| an object declared as volatile sig_atomic_t, or the signal
| handler calls any function in the standard library other
| than the abort function, the _Exit function, or the signal
| function with the first argument equal to the signal number
| corresponding to the signal that caused the invocation of
| the handler.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
More information about the Gcc
mailing list