views:

199

answers:

3

Is it possible to put a macro in a macro in c++?

Something like:

#define Something\
#ifdef SomethingElse\ //do stuff \
#endif\

I tried and it didn't work so my guess is it doesn't work, unless there's some sort of syntax that can fix it?

+6  A: 

No, but you can simply refactor this by pulling the #ifdef out as the toplevel, and using two different #define Something ... versions for the true and false branches of the #ifdef.

Alex Martelli
+6  A: 

Macros, yes. Preprocessor directives, which are what you posted, no

Michael Mrozek
+2  A: 

No. I answered this in http://stackoverflow.com/questions/2506167/c-macros-with-memory

If you want to inspect or alter the preprocessing environment, in other words to define a preprocessing subroutine rather than a string-replacement macro, you need to use a header, although the legitimate reasons for doing so are few and far between.

Potatoswatter
Huh, SO notified me that my change clobbered someone's edit. Sorry about that, feel free to redo.
Potatoswatter