Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top