Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
COLLAPSE_STATIC_LOCALS.cpp
Go to the documentation of this file.
1// checking static locals in inline code
2
3
25#if 0 // guard invalid preprocessor symbol below
26
27 // establish a dependency on collapse_static_locals.lib.*
28# ifndef _RWSTD_NO_collapse_static_locals.lib
29
30 // link this compiled translation unit with the lib below
31 // LDOPTS = collapse_static_locals.lib$(LIBSUFFIX)
32
33# endif // _RWSTD_NO_collapse_static_locals.lib
34#endif // 0
35
36
37// also defined in collapse_static_locals.lib.cpp
38inline int foo ()
39{
40 // multiple instances of `i' must be collapsed
41 static int i = 0;
42 return i++;
43}
44
45// bar() returns foo()
46extern int bar ();
47
48
49int main ()
50{
51 // compilers that corectly collapse static locals will
52 // behave as commented below (others will return 0 from bar())
53
54 int i = foo (); // returns 0
55 int j = bar (); // should return 1
56
57 return !(i != j);
58}
#define i
Definition 17.names.cpp:126
#define j
Definition 17.names.cpp:127