Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
NO_INT_TRAPS.cpp
Go to the documentation of this file.
1// checking if integer math traps
2
3
25#include "nodbg.h"
26
27
28#if defined (_MSC_VER)
29# define TRY __try
30# define EXCEPT(expr) __except (expr)
31#else // not MSVC
32# define TRY if (1)
33# define EXCEPT(ignore) else if (0)
34#endif // _MSC_VER
35
36
37int get_int (int);
38
39
40volatile int int_zero;
41volatile int int_one;
42
43
44int main (int argc, char*[])
45{
46 nodbg ();
47
48 // test expects to be called with no command line arguments
49 // i.e., (argc < 2) is expected to hold
50
51 // argc used to try to foil optimizers
52 int_zero = get_int (argc);
53 int_one = get_int (argc);
54
55 int result [2];
56
57 TRY {
58 // use both division and modulo to try to foil optimizers
59 result [0] = int_one / int_zero;
60 result [1] = int_one % int_zero;
61 }
62 EXCEPT (1) {
63 return 1;
64 }
65
66 // NEGATIVE test: successful exit status indicates a failure
67 return argc < 2 ? result [0] : result [1];
68}
69
70// use volatile to try to foil optimizers
71volatile int int_value;
72
73// use recursion to try to foil optimizers
74int get_int (int arg)
75{
76 if (1 < arg)
77 return get_int (arg - 1) + get_int (arg - 2);
78
79 const int value = int_value;
80
81 ++int_value;
82
83 return value;
84}
volatile int result
T value(const T &val)
#define main
#define EXCEPT(ignore)
volatile int int_zero
volatile int int_value
#define TRY
int get_int(int)
volatile int int_one
void nodbg()
Definition nodbg.h:52
int arg
Definition locale.cpp:2806