[fpc-pascal]trouble with {$IF ...}
Peter Vreman
peter at freepascal.org
Wed Feb 4 11:58:14 CET 2004
> I would like to do some very basic boolean operations within compiler
> directives. $IF does not seem to work reliably. See below:
>
> C:\fpc\test>fpc directive_test -Sm
> Free Pascal Compiler version 1.0.10 [2003/06/27] for i386
> [...]
> User defined: =========================
> User defined: $define x:=17
> User defined: !!! (x=5) = TRUE even though i set x:=17
> User defined: . (x>50) = false (good, x=17)
> User defined: !!! (x<50) = FALSE even though i set x:=17
> User defined: !!! ($if 1 AND 0) = TRUE
> User defined: =========================
> User defined: $define zero:=0
> User defined: !!! ($if zero) = TRUE
> User defined: !!! ($if 0) = TRUE
> User defined: and now the exact same test again...
> User defined: . ($if 0) = false
> User defined: =========================
> User defined: $define apples
> User defined: !!! ($ifdef oranges or apples) = FALSE :-(
> User defined: =========================
> Linking directive_test.exe
> 68 Lines compiled, 1.2 sec
>
> I know boolean operators are not supported for $ifdef, but it would sure
> be nice.
This is even not supported in C. $ifdef is just a shortcut for $if
defined(<name>). You must us '$if defined(oranges) or defined(apples)'.
The marcos work correct in the current development version 1.9.3:
Free Pascal Compiler version 1.9.3 [2004/02/04] for i386
Copyright (c) 1993-2004 by Florian Klaempfl
Target OS: Win32 for i386
Compiling p.pp
User defined: =========================
User defined: $define x:=17
User defined: . (x=5) = false (good, x=17)
User defined: . (x>50) = false (good, x=17)
User defined: . (x<50) = true (good, x=17)
User defined: . ($if 1 AND 0) = false
User defined: =========================
User defined: $define zero:=0
User defined: . zero returned false
User defined: . ($if 0) = false
User defined: and now the exact same test again...
User defined: . ($if 0) = false
User defined: =========================
User defined: $define apples
User defined: !!! ($ifdef oranges or apples) = FALSE :-(
User defined: =========================
Linking p.exe
69 Lines compiled, 0.2 sec
More information about the fpc-pascal
mailing list