[fpc-devel] Is that intended: {$define 2} ... {$IFDEF 2}

Michael Van Canneyt michael at freepascal.org
Sat Dec 6 11:10:06 CET 2025



On Fri, 5 Dec 2025, Martin Frb via fpc-devel wrote:

> $define/$Ifdef don't just take (name) identifiers.
>
> They also take numbers, <strike>and expressions. </strike>
>
> Well actually, numbers.
> {$define 2}
> {$IFDEF 2} .... {$ENDIF}
>
>
> The below at first looked like expressions too (but as literal text)
> But like any directive, it parses until it has the directive (in this case 
> the first ident "2" and ignores the rest "+1" as comment.
>
> The below is just about the "2":
> {$define 2+1}
> {$IFDEF 1+2} not compiled {$ENDIF}
> {$IFDEF 2+1} foo; {compiled} {$ENDIF}
> {$IFDEF 2+ 1} foo; {compiled} {$ENDIF} // note the space

Seriously ?

The inventive ways by which people try to shoot themselves in the foot never
cease to amaze me...

They do it with lots of enthusiasm, it seems :-)

Michael.


More information about the fpc-devel mailing list