It is not possible to have a macro to expand to something that contains the defined
keyword:
If the token defined
is generated as a result of this replacement
process or use of the defined
unary operator does not match one of the
two specified forms prior to macro replacement, the behavior is
undefined.
So you can't do it with defined
. If you are willing to relax that constraint by just testing the value of FOO_A_
, FOO_B_
, ... there are ways to do this by using P99. E.g just doing a logical or of a list of variables would be
#if P99_ORS(A, B, C)
...
#endif
where the P99_ORS
expression expands to
((((A) || (B))) || (C))
and is then evaluated for #if
the expression.
There would also be ways to expand that first into a token list of your liking, if you want to do some macro programming
#define P00_NAME_X(NAME, X, I) P99_PASTE2(NAME, X)
#define CONDITION(NAME, ...) P99_ORS(P99_FOR(FOO_, P99_NARG(__VA_ARGS__), P00_SEQ, P00_NAME_X, __VA_ARGS__))
such that
CONDITION(A, B, C, toto);
would expand to
((((((FOO_A) || (FOO_B))) || (FOO_C))) || (FOO_toto));