c - Stops working when trying to `longjmp` from a signal handler -


here's code:

#include <stdio.h> #include <setjmp.h> #include <signal.h>  jmp_buf buf;  void handler(int s);  int main(int argc, char **argv) {     signal(sigint, handler);     if (setjmp(buf)) {         printf("back again!\n");         return 0;     } else {         printf("first here.\n");     }      (;;) {} }  void handler(int s) {     longjmp(buf, 1); } 

i compile under vs 2012 on windows 8 64bit. every time press control+c, program doesn't reboot expected stops working. me?

from current c standard:

if signal occurs other result of calling abort or raise function, behavior undefined if signal handler refers object static or thread storage duration not lock-free atomic object other assigning value object declared volatile sig_atomic_t, or signal handler calls function in standard library other abort function, _exit function, quick_exit function, or signal function first argument equal signal number corresponding signal caused invocation of handler.

you using object static storage duration not in list of allowed types (buf) , use function of standard library not in list of allowed functions (longjmp).


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -