Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error stray '#' in program

I would like to define a macro based on whether -std=c++0x is used. If I try the macro below I have error error stray '#' in program.

Is the code below incorrect / is it allowed C++ to use preprocessor #if / #endif within a #define?

   #define DEF_ME (p) \
   #if  __GXX_EXPERIMENTAL_CXX0X__ \
   #endif

I am using g++ 4.4.7 in Linux.

like image 205
Abruzzo Forte e Gentile Avatar asked Feb 10 '14 10:02

Abruzzo Forte e Gentile


1 Answers

Is the code below incorrect / is it allowed C++ to use preprocessor #if / #endif within a #define?

No, that’s not allowed. But you can use the opposite to get the same result:

#if  __GXX_EXPERIMENTAL_CXX0X__
#   define DEF_ME (p) one way
#else
#   define DEF_ME (p) another way
#endif
like image 192
Konrad Rudolph Avatar answered Sep 22 '22 22:09

Konrad Rudolph