| 1 |
|
| 2 | // nodefaultlib build: cl -Zi sigsegv.cpp /link /nodefaultlib
|
| 3 |
|
| 4 | #ifdef USE_CRT
|
| 5 | #include <stdio.h>
|
| 6 | #else
|
| 7 | int main();
|
| 8 | extern "C"
|
| 9 | {
|
| 10 | int _fltused;
|
| 11 | void mainCRTStartup() { main(); }
|
| 12 | void printf(const char*, ...) {}
|
| 13 | }
|
| 14 | #endif
|
| 15 |
|
| 16 | void crash(bool crash_self)
|
| 17 | {
|
| 18 | printf("Before...\n" );
|
| 19 | if(crash_self)
|
| 20 | {
|
| 21 | printf("Crashing in 3, 2, 1 ...\n" );
|
| 22 | *(volatile int*)nullptr = 0;
|
| 23 | }
|
| 24 | printf("After...\n" );
|
| 25 | }
|
| 26 |
|
| 27 | int foo(int x, float y, const char* msg)
|
| 28 | {
|
| 29 | bool flag = x > y;
|
| 30 | if(flag)
|
| 31 | printf("x = %d, y = %f, msg = %s\n" , x, y, msg);
|
| 32 | crash(crash_self: flag);
|
| 33 | return x << 1;
|
| 34 | }
|
| 35 |
|
| 36 | int main()
|
| 37 | {
|
| 38 | foo(x: 10, y: 3.14, msg: "testing" );
|
| 39 | }
|
| 40 |
|
| 41 | |