[gfortran] add SIGNAL and ALARM intrinsics
FX Coudert
fxcoudert@gmail.com
Sat Nov 19 19:16:00 GMT 2005
> +#ifdef HAVE_SIGNAL
> + if (status != NULL)
> + *status = (int) signal (*number, handler);
> + else
> + signal (*number, handler);
> +#else
>
> (twice in that file) can't be right. signal returns a function pointer
> or SIG_ERR. Casting a pointer to int is wrong.
Well, I'm just doing things the way g77 did. The g77 docs explicitly say:
---------------
Due to the side effects performed by this intrinsic, the function form
is not recommended.
Warning: If the returned value is stored in an INTEGER(KIND=1) (default
INTEGER) argument, truncation of the original return value occurs on
some systems (such as Alphas, which have 64-bit pointers but 32-bit
default integers), with no warning issued by g77 under normal circumstances.
Therefore, the following code fragment might silently fail on some systems:
INTEGER RTN
EXTERNAL MYHNDL
RTN = SIGNAL(signum, MYHNDL)
...
! Restore original handler:
RTN = SIGNAL(signum, RTN)
The reason for the failure is that `RTN' might not hold all the
information on the original handler for the signal, thus restoring an
invalid handler. This bug could manifest itself as a spurious run-time
failure at an arbitrary point later during the program's execution, for
example.
---------------
I think it's clear enough. Though, if people think it's better to change
this behaviour, we could do it.
FX
More information about the Gcc-patches
mailing list