Does anyone know how to, or if it's even possible to, create a variadic macro that expands to 0 if it's argument is not a defined macro, but expands to 1 if it's argument is a defined macro? (I'm using c99.)
#define BOB
#define SUE 45
#define IS_DEFINED(...) ???
IS_DEFINED(JOE) <---- expands to 0
IS_DEFINED(BOB) <---- expands to 1 (it's okay if this one doesn't work)
IS_DEFINED(SUE) <---- expands to 1
EDIT: I specifically don't want any #if
-related solutions... it needs to be a variadic macro (if that's possible) so I can do things like this:
#define CAT_(x, y) x ## y
#define CAT(x, y) CAT_(x, y)
#define CLEANUP0(...) ABC <--- treats __VA_ARGS__ one way
#define CLEANUP1(...) XYZ <--- treats __VA_ARGS__ a different way
#define CLEANUP(...) CAT(CLEANUP, IS_DEFINED(DEFAULT))(__VA_ARGS__)
Where ABC
& XYZ
are placeholders for other expansions that treat __VA_ARGS__
very differently.