why this signal handler is called infinitely

Posted by lz_prgmr on Stack Overflow See other posts from Stack Overflow or by lz_prgmr
Published on 2010-12-26T07:38:32Z Indexed on 2010/12/26 7:54 UTC
Read the original article Hit count: 185

Filed under:
|

I am using Mac OS 10.6.5, g++ 4.2.1. And meet problem with following code:

#include <iostream>
#include <sys/signal.h>
using namespace std;

void segfault_handler(int signum)
{
    cout << "segfault caught!!!\n";
}

int main()
{
    signal(SIGSEGV, segfault_handler);

    int* p = 0;
    *p = 100;

    return 1;
}

It seems the segfault_handler is called infinitely and keep on print:

segfault caught!!!
segfault caught!!!
segfault caught!!!
...

I am new to Mac development, do you have any idea on what happened?

© Stack Overflow or respective owner

Related posts about mac

Related posts about signal