1b8e80941Smrg/* Macro using defined with a hard-coded identifier (no parentheses) */
2b8e80941Smrg#define is_foo_defined defined /*...*/ foo
3b8e80941Smrg#undef foo
4b8e80941Smrg#if is_foo_defined
5b8e80941Smrgfailure
6b8e80941Smrg#else
7b8e80941Smrgsuccess
8b8e80941Smrg#endif
9b8e80941Smrg#define foo
10b8e80941Smrg#if is_foo_defined
11b8e80941Smrgsuccess
12b8e80941Smrg#else
13b8e80941Smrgfailure
14b8e80941Smrg#endif
15b8e80941Smrg
16b8e80941Smrg/* Macro using defined with a hard-coded identifier within parentheses */
17b8e80941Smrg#define is_foo_defined_parens defined /*...*/ ( /*...*/ foo /*...*/ ) //
18b8e80941Smrg#define foo
19b8e80941Smrg#if is_foo_defined_parens
20b8e80941Smrgsuccess
21b8e80941Smrg#else
22b8e80941Smrgfailure
23b8e80941Smrg#endif
24b8e80941Smrg#undef foo
25b8e80941Smrg#if is_foo_defined_parens
26b8e80941Smrgfailure
27b8e80941Smrg#else
28b8e80941Smrgsuccess
29b8e80941Smrg#endif
30b8e80941Smrg
31b8e80941Smrg/* Macro using defined with an argument identifier (no parentheses) */
32b8e80941Smrg#define is_defined(arg) defined /*...*/ arg
33b8e80941Smrg#define foo bar
34b8e80941Smrg#undef bar
35b8e80941Smrg#if is_defined(foo)
36b8e80941Smrgfailure
37b8e80941Smrg#else
38b8e80941Smrgsuccess
39b8e80941Smrg#endif
40b8e80941Smrg#define bar bar
41b8e80941Smrg#if is_defined(foo)
42b8e80941Smrgsuccess
43b8e80941Smrg#else
44b8e80941Smrgfailure
45b8e80941Smrg#endif
46b8e80941Smrg
47b8e80941Smrg/* Macro using defined with an argument identifier within parentheses */
48b8e80941Smrg#define is_defined_parens(arg) defined /*...*/ ( /*...*/ arg /*...*/ ) //
49b8e80941Smrg#define foo bar
50b8e80941Smrg#define bar bar
51b8e80941Smrg#if is_defined_parens(foo)
52b8e80941Smrgsuccess
53b8e80941Smrg#else
54b8e80941Smrgfailure
55b8e80941Smrg#endif
56b8e80941Smrg#undef bar
57b8e80941Smrg#if is_defined_parens(foo)
58b8e80941Smrgfailure
59b8e80941Smrg#else
60b8e80941Smrgsuccess
61b8e80941Smrg#endif
62b8e80941Smrg
63b8e80941Smrg/* Multiple levels of macro resulting in defined */
64b8e80941Smrg#define X defined A && Y
65b8e80941Smrg#define Y defined B && Z
66b8e80941Smrg#define Z defined C
67b8e80941Smrg#define A
68b8e80941Smrg#define B
69b8e80941Smrg#define C
70b8e80941Smrg#if X
71b8e80941Smrgsuccess
72b8e80941Smrg#else
73b8e80941Smrgfailure
74b8e80941Smrg#endif
75b8e80941Smrg#undef A
76b8e80941Smrg#if X
77b8e80941Smrgfailure
78b8e80941Smrg#else
79b8e80941Smrgsuccess
80b8e80941Smrg#endif
81b8e80941Smrg#define A
82b8e80941Smrg#undef B
83b8e80941Smrg#if X
84b8e80941Smrgfailure
85b8e80941Smrg#else
86b8e80941Smrgsuccess
87b8e80941Smrg#endif
88b8e80941Smrg#define B
89b8e80941Smrg#undef C
90b8e80941Smrg#if X
91b8e80941Smrgfailure
92b8e80941Smrg#else
93b8e80941Smrgsuccess
94b8e80941Smrg#endif
95