/* Demonstrate a SEGV * We can't use the handler to recover from it. */ #include #include #include float *x = NULL; // assume global variable x has been allocated. print its value. void do_something() { printf( "in do_something\n" ); // the error happens inside printf printf("%.2f\n", *x ); } void seghandler(int signal) { printf("\nCaught seg fault %d\n", signal); exit(-1); // this doesn't help: // x = malloc( sizeof(int) ); // *x = 1; //return; } int main(int argc, char *argv[]) { signal(SIGSEGV, seghandler); do_something(); return 0; }