Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
Main Page
Related Pages
Topics
Namespaces
Data Structures
Files
File List
Globals
EXTERNAL_HEADERS
RSL
etc
config
src
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
37
int
get_int
(
int
);
38
39
40
volatile
int
int_zero
;
41
volatile
int
int_one
;
42
43
44
int
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
71
volatile
int
int_value
;
72
73
// use recursion to try to foil optimizers
74
int
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
}
result
volatile int result
Definition
18.limits.traps.stdcxx-624.cpp:35
value
T value(const T &val)
Definition
26.valarray.cassign.cpp:139
main
#define main
Definition
BAD_ALLOC_COPY_CTOR.cpp:32
EXCEPT
#define EXCEPT(ignore)
Definition
NO_INT_TRAPS.cpp:33
int_zero
volatile int int_zero
Definition
NO_INT_TRAPS.cpp:40
int_value
volatile int int_value
Definition
NO_INT_TRAPS.cpp:71
TRY
#define TRY
Definition
NO_INT_TRAPS.cpp:32
get_int
int get_int(int)
Definition
NO_INT_TRAPS.cpp:74
int_one
volatile int int_one
Definition
NO_INT_TRAPS.cpp:41
nodbg.h
nodbg
void nodbg()
Definition
nodbg.h:52
arg
int arg
Definition
locale.cpp:2806
Generated by
1.9.8