This function-like macro definition has no use because it is indeed not used anywhere in the array initializer until its undefinition at the end of the initializer list.
For example Clang complains this too:
"warning: macro is not used [-Wunused-macros]"
As result after the preprocessing, the code is equivalent to:
int array[] = { 10, 20, };
I guess the intention was to define a first element and initialize it with the value of a
by the use of conditional compilation directives, so that array
is composed of 3 elements instead of 2, with the first element containing the value of a
.
This would be more appropriate for this case:
MACRO
is defined before its use/check in the array initializer list. If it was defined, a
is inserted into the initializer. Since MACRO
has no further use, we can #undef
it after the initialization.
#define MACRO
#define a 5
int array[] = {
#ifdef MACRO
a,
#endif
#undef MACRO
10,
20,
};
Note: a
could also be a const
qualified integer object than a preprocessor macro: const int a = 5;
.