2

Look at the code in 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

API_TYPE could only be defined as 1,2,3. It is wrong if be defined as other value. I can write some illegal code in #else path. But it is not perfect. Is there any command or method to stop the pre-compile process if it goes #else path?

4

2 に答える 2

7

を挿入する#error "Error message"と、前処理が停止し、コンパイルも開始されません。

于 2012-08-10T11:46:38.117 に答える
2

#errorを使用する

http://en.wikipedia.org/wiki/C_preprocessor#User-defined_compilation_errors

于 2012-08-10T11:47:55.920 に答える