if and #if
#2

#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:

Код:
#define LIMIT 10
 
if (LIMIT < 10)
{
	printf("Limit too low");
}
which would compile as :

Код:
if (10 < 10)
{
	printf("Limit too low");
}
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:

Код:
#define LIMIT 10
 
#if LIMIT < 10
	#error Limit too low
#endif
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.
Reply


Messages In This Thread
if and #if - by [eLg]elite - 12.01.2016, 17:20
Re: if and #if - by -CaRRoT - 12.01.2016, 17:33
Re: if and #if - by [eLg]elite - 12.01.2016, 17:39
Re: if and #if - by Vince - 12.01.2016, 19:37
Re: if and #if - by [eLg]elite - 12.01.2016, 19:41

Forum Jump:


Users browsing this thread: 1 Guest(s)