The conditional preprocessor does not work, as in the first example.
It works with constants, understand? During compilation, it considers various conditions and places / excludes the source code according to it.
For instance:
#define HAS_COMPARISON int main() { #ifdef HAS_COMPARISON int i = 0; if(i == 0) std::cout << "This"; else #else std::cout << "That"; #endif }
Using the define set, it will set the i variable and perform a comparison ... In short, it will output This . If you comment on this definition, the whole block will not be in your program, which means that it will always output That , without setting a variable or without performing a comparison.
This is the most common use of the preprocessor. You can also define values ββand compare them to have the behavior of a variable with the same definition, but this is another problem.
Once again: the conditional preprocessor is evaluated at compile time, condition variables are evaluated at runtime.
source share