문제

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?

도움이 되었습니까?

해결책

You can insert #error "Error message", which will stop preprocessing and a compilation won't even begin.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top