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;
mainCRTStartup()11     void mainCRTStartup() { main(); }
printf(const char *,...)12     void printf(const char*, ...) {}
13 }
14 #endif
15 
crash(bool crash_self)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 
foo(int x,float y,const char * msg)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(flag);
33     return x << 1;
34 }
35 
main()36 int main()
37 {
38     foo(10, 3.14, "testing");
39 }
40 
41