| Last change
 on this file since 3890 was             3593, checked in by bird, 18 years ago | 
        
          | 
Fixed some unwinding stuff on msc+amd64.
 | 
        
          | File size:
            983 bytes | 
      
      
| Line |  | 
|---|
| 1 |  | 
|---|
| 2 | #include <setjmp.h> | 
|---|
| 3 | #include <time.h> | 
|---|
| 4 |  | 
|---|
| 5 | /* just try trick the compiler into not optimizing stuff by | 
|---|
| 6 | making it "uncertain" which path to take. */ | 
|---|
| 7 | int always_true(void) | 
|---|
| 8 | { | 
|---|
| 9 | time_t t = time(NULL); | 
|---|
| 10 | if (t == time(NULL)) | 
|---|
| 11 | return 1; | 
|---|
| 12 | if (t != time(NULL)) | 
|---|
| 13 | return 1; | 
|---|
| 14 | if (t == time(NULL)) | 
|---|
| 15 | return 1; | 
|---|
| 16 | if (t != time(NULL)) | 
|---|
| 17 | return 1; | 
|---|
| 18 | return 0; | 
|---|
| 19 | } | 
|---|
| 20 |  | 
|---|
| 21 | jmp_buf g_JmpBuf; | 
|---|
| 22 |  | 
|---|
| 23 | int onelevel(void) | 
|---|
| 24 | { | 
|---|
| 25 | if (always_true()) | 
|---|
| 26 | longjmp(g_JmpBuf, 1); | 
|---|
| 27 | return 0; | 
|---|
| 28 | } | 
|---|
| 29 |  | 
|---|
| 30 |  | 
|---|
| 31 | int twolevels_inner(void) | 
|---|
| 32 | { | 
|---|
| 33 | if (always_true()) | 
|---|
| 34 | longjmp(g_JmpBuf, 1); | 
|---|
| 35 | return 0; | 
|---|
| 36 | } | 
|---|
| 37 |  | 
|---|
| 38 | int twolevels_outer(void) | 
|---|
| 39 | { | 
|---|
| 40 | int rc; | 
|---|
| 41 | always_true(); | 
|---|
| 42 | rc = twolevels_inner(); | 
|---|
| 43 | always_true(); | 
|---|
| 44 | return rc; | 
|---|
| 45 | } | 
|---|
| 46 |  | 
|---|
| 47 |  | 
|---|
| 48 | int main() | 
|---|
| 49 | { | 
|---|
| 50 | int rc = 1; | 
|---|
| 51 |  | 
|---|
| 52 | /* first */ | 
|---|
| 53 | if (!setjmp(g_JmpBuf)) | 
|---|
| 54 | rc = onelevel(); | 
|---|
| 55 |  | 
|---|
| 56 | /* second */ | 
|---|
| 57 | if (!setjmp(g_JmpBuf)) | 
|---|
| 58 | rc = twolevels_outer(); | 
|---|
| 59 |  | 
|---|
| 60 | return rc != 1; | 
|---|
| 61 | } | 
|---|
| 62 |  | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.