Is there a way to have the C Preprocessor resolve macros in an #error statement?

后端 未结 3 1299
甜味超标
甜味超标 2021-02-20 04:57

Just as the title says. I want to use a preprocessor macro in the text of an #error statement:

#define SOME_MACRO 1

#if SOME_MACRO != 0
    #error \"SOME_MACRO          


        
3条回答
  •  无人共我
    2021-02-20 05:34

    #define INVALID_MACRO_VALUE2(x) 
    #define INVALID_MACRO_VALUE(x) INVALID_MACRO_VALUE2(x)
    
    #if SOME_MACRO != 0
      #include INVALID_MACRO_VALUE(SOME_MACRO)
    #endif
    

    generates "Cannot open include file: 'invalid_macro_value_1': No such file or directory" in Visual Studio 2005 and probably similar messages on other compilers.

    This doesn't answer your question directly about using #error, but the result is similar.

提交回复
热议问题