views:

402

answers:

2

How do I at compiletime undefine a compiler macro using gcc. I tried some compile args to gcc like -D but I cant get to see the "not defined" message.

Thanks

#include <iostream>

#define MYDEF


int main(){
#ifdef MYDEF
  std::cout<<"defined\n";
#else
  std::cout<<"not defined\n";
#endif

}
+2  A: 

http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/Preprocessor-Options.html#Preprocessor-Options

The -U options seemed like what you could have needed... but then again you can't override a definition contained in your source code without resorting to more preprocessor directives.

jldupont
+2  A: 

You can use the -U option with gcc, but it won't undefine a macro defined in your source code. As far as I know, there's no way to do that.

dcp
Yeah, `-U` only works with macros also defined on the command line. You can't undefine a macro defined in code from the CL.
Marc W