Go to the first, previous, next, last section, table of contents.


Signal Intrinsic (function)

Signal(Number, Handler)

Signal: INTEGER(KIND=7) function.

Number: INTEGER; scalar; INTENT(IN).

Handler: Signal handler (INTEGER FUNCTION or SUBROUTINE) or dummy/global INTEGER(KIND=1) scalar.

Intrinsic groups: badu77.

Description:

If Handler is a an EXTERNAL routine, arranges for it to be invoked with a single integer argument (of system-dependent length) when signal Number occurs. If Handler is an integer, it can be used to turn off handling of signal Number or revert to its default action. See signal(2).

Note that Handler will be called using C conventions, so the value of its argument in Fortran terms is obtained by applying %LOC() (or LOC()) to it.

The value returned by signal(2) is returned.

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.

Warning: Use of the libf2c run-time library function `signal_' directly (such as via `EXTERNAL SIGNAL') requires use of the %VAL() construct to pass an INTEGER value (such as `SIG_IGN' or `SIG_DFL') for the Handler argument.

However, while `RTN = SIGNAL(signum, %VAL(SIG_IGN))' works when `SIGNAL' is treated as an external procedure (and resolves, at link time, to libf2c's `signal_' routine), this construct is not valid when `SIGNAL' is recognized as the intrinsic of that name.

Therefore, for maximum portability and reliability, code such references to the `SIGNAL' facility as follows:

INTRINSIC SIGNAL
...
RTN = SIGNAL(signum, SIG_IGN)

g77 will compile such a call correctly, while other compilers will generally either do so as well or reject the `INTRINSIC SIGNAL' statement via a diagnostic, allowing you to take appropriate action.

For information on other intrinsics with the same name: See section Signal Intrinsic (subroutine).


Go to the first, previous, next, last section, table of contents.