2012-08-10 87 views
2

看代碼config.h中:如何在C中停止預編譯?

#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 

API_TYPE只能被定義爲1,2,3。如果被定義爲其他值是錯誤的。 我可以在#else路徑中寫入一些非法代碼。但它並不完美。是否有任何命令或方法停止預編譯過程,如果它去#else路徑?

回答

7

您可以插入#error "Error message",這將停止預處理,編譯甚至不會開始。

+0

謝謝您非常感謝! – qiushuitian 2012-08-10 12:06:51