-
Macros inside of macros
Hey, I am trying to #define something inside of one of my macros. Here is an example of my code:
Code:
int unused;
#define REGISTER(a) a ## _REGISTER
#define REGISTER_OUT(a) \
#ifndef (REGISTER(a)) \
#define REGISTER(a) unused \
#endif // REGISTER_OUT
REGISTER_OUT(A1)
So I want to check if A1_REGISTER is defined, and if it is not, define it as the int unused. How can I do this, as the above code does not work.
-
Unfortunately -- you can't do that, per se. That is, you can't use preprocessor directives like #define inside macros. I've often wanted to, but you can't. :)
However, you might be able to solve your problem, with something like this.
Code:
#ifndef A1_REGISTER
#define REGISTER(a) unused
#else
#define REGISTER(a) a ## _REGISTER
#endif // A1_REGISTER
-
Wait some people at the http://www.ioccc.org have used shamelesly defines within macros. Maybe you should check out their source even though it's a bit obfuscated...