12.01.2016, 17:33
#if is known as a directive, its a preprocessor in PAWN and you can use them to check specific conditions.
You can choose what to compile and what to not, ex:
which would compile as :
The compiler knows that its not true and never will be so it would give you a constant expression warning, so the only reason you would want to keep this code if someone changes the limit and recompiles, so that's when #if comes in play, Unlike normal if which give a warning if the expression is constant, #if expressions MUST be constant. So:
If the limit is too small, it would give you a compiler error instead of you having to manually test it as it would check the code.
Source: Wiki for examples.
You can choose what to compile and what to not, ex:
Код:
#define LIMIT 10 if (LIMIT < 10) { printf("Limit too low"); }
Код:
if (10 < 10) { printf("Limit too low"); }
Код:
#define LIMIT 10 #if LIMIT < 10 #error Limit too low #endif
Source: Wiki for examples.