【问题标题】:Error stray '#' in program程序中出现错误杂散“#”
【发布时间】:2014-02-10 10:00:38
【问题描述】:

我想根据是否使用-std=c++0x 来定义一个宏。 如果我尝试下面的宏,我会遇到错误error stray '#' in program。

下面的代码是否不正确/是否允许 C++ 在 #define 中使用预处理器 #if / #endif ?

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

我在 Linux 中使用 g++ 4.4.7。

【问题讨论】:

    标签: c++ macros g++ c-preprocessor


    【解决方案1】:

    下面的代码是否不正确/是否允许 C++ 在 #define 中使用预处理器 #if / #endif?

    不,这是不允许的。但是你可以使用相反的结果来获得相同的结果:

    #if  __GXX_EXPERIMENTAL_CXX0X__
    #   define DEF_ME (p) one way
    #else
    #   define DEF_ME (p) another way
    #endif
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-07
      • 2023-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多