Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: added an implementation note to justify the NCCE

...

If the value of i is cached, the while loop may never terminate, even on the program . When compiled on gcc with the -O optimization flag, the program fails to terminate even upon receiving a SIGINT.

Code Block
bgColor#ffcccc
#include <signal.h>

sig_atomic_t i;

void handler(int signum) {
  i = 0;
}

int main(void) {
  i = 1;
  signal(SIGINT, handler);
  while (i) {
   /* do something */
  }
  return 0;
}

...