English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

#include
#include
#include
#include

void segment_fault_handler(int x)
{

*((int *)((int)(&x))+0)=x;
printf("line 17");

}


int main()
{
int r2 = 0;

signal(SIGSEGV, segment_fault_handler);


r2 = *( (int *) 0 );


printf("Ran instruction\n");

return 0;
}


this compiles and but when i try to run the .exe file i get a segmentation fault error, it does print out "Line 17" once, can someone please try to help debug this.

2007-02-28 12:44:07 · 1 answers · asked by Help me Pick my Brain 2 in Computers & Internet Programming & Design

1 answers

it looks like it is doing exactly what you want it to do.

Trying to dereference the null pointer will case a seg fault. That's handled but your handler doesn't really do anything so the program will still crash. You can't just return to where the error occurred.

2007-02-28 12:59:06 · answer #1 · answered by sspade30 5 · 1 0

fedest.com, questions and answers