Equivalent of segfault on Windows/MSVC?

Viewed 530

On Linux, the following code:

long* p = (long*)reinterpret_cast<void*>(0x634963963496034) // random memory address
std::cout << *p;

will likely cause a read of memory that hasn't been allocated, and the program will raise a SIGSEGV signal. Otherwise known as a segfault. (An action can be attached via sigaction(2)).

Is there an equivalent mechanism on Windows / MSVC ?

What will the above code do on Windows? Is there any way to trap this memory access violation, and run a user-provided function?

2 Answers

What I was looking for was SetUnhandledExceptionFilter. SetUnhandledExceptionFilter on Windows is equivalent to sigaction on Linux for this use case.

Related