S
Spiros Bousbouras
In 7.14.1.1 par.5 we read
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,
So that means that you are not allowed to read the value of such
an object. So for example
static volatile sig_atomic_t a ;
void handler(int i) {
a = 2 ; /* OK */
a++ ; /* UB */
if ( a == 3 ) { /* UB */
...
}
}
Have I got it right ? If yes can anyone give me some insight on
why writing is allowed but reading is not ?
Par. 3:
If and when the function returns, if the value of sig is
SIGFPE, SIGILL, SIGSEGV, or any other implementation-defined
value corresponding to a computational exception, the
behavior is undefined; otherwise the program will resume
execution at the point it was interrupted.
If the signal was generated by raise() why is it not ok for the
handler to return since no actual computational exception
occurred ?
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,
So that means that you are not allowed to read the value of such
an object. So for example
static volatile sig_atomic_t a ;
void handler(int i) {
a = 2 ; /* OK */
a++ ; /* UB */
if ( a == 3 ) { /* UB */
...
}
}
Have I got it right ? If yes can anyone give me some insight on
why writing is allowed but reading is not ?
Par. 3:
If and when the function returns, if the value of sig is
SIGFPE, SIGILL, SIGSEGV, or any other implementation-defined
value corresponding to a computational exception, the
behavior is undefined; otherwise the program will resume
execution at the point it was interrupted.
If the signal was generated by raise() why is it not ok for the
handler to return since no actual computational exception
occurred ?