Parts of my code depend on the value of a preprocessor symbol:
int a()
{
#if SDK_VERSION >= 3
return 1;
#else
return 2;
#endif
}
The comparison depends of the value of SDK_VERSION. It is expected to be a integer or something that compares to a integer, in this case, 3. If SDK_VERSION is something that cannot be compared to a integer, there will be a compile error.
Is there a way to abort the compilation if SDK_VERSION is not of an expected type? For example:
#if type(SDK_VERSION) != int # Does not compile, I know
#error "SDK_VERSION must be an integer."
#endif
Use template to generate such error:
This code would generate compilation error, having the following string in it, if the
SDK_VERSIONis not int:See these demo:
#define SDK_VERSION 1.0)#define SDK_VERSION 1)And also notice the error message in the first case. It prints this: