VirtualBox

source: kStuff/trunk/kProfiler2/tstlongjmp.c@ 2

Last change on this file since 2 was 2, checked in by bird, 17 years ago

Imported http://svn.netlabs.org/repos/libc/trunk/kStuff, revision 3612.

  • Property svn:keywords set to Id Revision
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. */
7int 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
21jmp_buf g_JmpBuf;
22
23int onelevel(void)
24{
25 if (always_true())
26 longjmp(g_JmpBuf, 1);
27 return 0;
28}
29
30
31int twolevels_inner(void)
32{
33 if (always_true())
34 longjmp(g_JmpBuf, 1);
35 return 0;
36}
37
38int twolevels_outer(void)
39{
40 int rc;
41 always_true();
42 rc = twolevels_inner();
43 always_true();
44 return rc;
45}
46
47
48int 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.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette