Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2025-12

Is that intended: {$define 2} ... {$IFDEF 2}

5 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Martin Frb

$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

See also
https://forum.lazarus.freepascal.org/index.php/topic,72937.0.html

Reply by email

Michael Van Canneyt
to Martin Frb
Martin Frb wrote 18 lines
$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.

Reply by email

Martin Frb
to Michael Van Canneyt
Michael Van Canneyt wrote 20 lines
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} > 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 :-)

Ok, so the docs says defines a "name" or "symbol", it does not refer to "identifier". Which means I guess numbers are in that scope.

And I just realised, the above can be used with macros.

{$macro on}
{$define 0=1}
begin
   write(random(123) / 0);

should work ... ;)

Reply by email

Michael Van Canneyt
to Martin Frb
Martin Frb wrote 24 lines
On 06/12/2025 11:10, Michael Van Canneyt via fpc-devel wrote: > > > 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} >> > > 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 :-) Ok, so the docs says defines a "name" or "symbol", it does not refer to "identifier". Which means I guess numbers are in that scope.

I doubt this is intentional, but if it makes you happy...

Michael.

Reply by email

Giuliano Colla
to Martin Frb: Ok, so the docs says defines a "name" or "symbol", it does not refer to "identifier".…

Il 07/12/25 10:05, Martin Frb via fpc-devel ha scritto:

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

I'm afraid that too many people don't realize that a computer is not "intelligent". It's nothing but a stupid very fast calculator, provided of means to tell it what keys to strike, called "programs". If the program tells "if you find "0" strike key 1", it will do it.

Writing a compiler which blocks human stupidity is an hopeless goal. As Einstein stated, it's impossible, "because human intelligence has a limit, while human stupidity has none".

Giuliano

Do not do to others as you would have them do to you.They might have different tastes.

Reply by email