如何在C中停止预编译?

qiu*_*ian 2 c conditional-compilation precompiled

查看config.h中的代码:

#if (API_TYPE == 1)
    #define URL_API @"https://dapi.xxx.com/1.1/"
#elif (API_TYPE == 2)
    #define URL_API @"https://tapi.xxx.com/1.1/"
#elif (API_TYPE == 3)
    #define URL_API @"https://api.xxx.com/1.1/"
#else
   // I want stop pre-compile if in here.
   // assert(0);
#endif
Run Code Online (Sandbox Code Playgroud)

API_TYPE只能定义为1,2,3.如果被定义为其他值则是错误的.我可以在#else路径中写一些非法代码.但它并不完美.是否有任何命令或方法停止预编译过程,如果它是#else路径?

Mak*_*zin 7

您可以插入#error "Error message",这将停止预处理,甚至不会开始编译.