Somewhere in my code, I have preprocessor definition
#define ZOOM_FACTOR 1
In another place I have
#ifdef ZOOM_FACTOR
#if (ZOOM_FACTOR == 1)
#define FONT_SIZE 8
#else
#define FONT_SIZE 12
#endif
#else
#define FONT_SIZE 8
#endif
The problem is when I change ZOOM_FACTOR value to floating point value, for example 1.5, I'm getting compile error C1017: invalid integer constant expression.
Does anyone know why am I getting this error and is there any way to make a comparison between integer and floating point number within preprocessor directive?
The error is because the language does not permit it.
As per the C++ standard, [cpp.cond]/1:
The expression that controls conditional inclusion shall be an integral constant expression.
Instead of defining ZOOM_FACTOR as floating point value 1.5, why not define it as a multiple of such value. For example, multiply with a constant such as 2 and then make your comparisons.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With