Sign in Join

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

Mailing lists / fpc-devel / 2017-04

Compiler bug in macro handling?

6 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

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

Giuliano Colla

Hi honourable fpc developers!

I found a strange error (both with fpc 2.6.4 and fpc 3.0.0, in Linux environment)

The following snippet of code:

{$MACRO ON}
{$define Positiva:=False;}
{$define Negativa:=True;}
.......
      if HDCOUNT0 >= COUNT0 then V_PIU0 := Positiva
       else V_PIU0 := Negativa;
  gives rise to a Fatal: syntax error: ";" expected but "ELSE" found.

But if I change the code into:

      if HDCOUNT0 >= COUNT0 then V_PIU0 := False
       else V_PIU0 := True;
  (which IMHO should be identical) it compiles without complaining.

Am I doing something wrong or it is a bug?

Giuliano

Reply by email

Michael Van Canneyt
to Giuliano Colla
Giuliano Colla wrote 24 lines
Hi honourable fpc developers! I found a strange error (both with fpc 2.6.4 and fpc 3.0.0, in Linux environment) The following snippet of code: {$MACRO ON} {$define Positiva:=False;} {$define Negativa:=True;} ....... if HDCOUNT0 >= COUNT0 then V_PIU0 := Positiva else V_PIU0 := Negativa; gives rise to a Fatal: syntax error: ";" expected but "ELSE" found. But if I change the code into: if HDCOUNT0 >= COUNT0 then V_PIU0 := False else V_PIU0 := True; (which IMHO should be identical) it compiles without complaining. Am I doing something wrong or it is a bug?
Try removing the semicolon:
{$define Positiva:=False}
{$define Negativa:=True}

Michael.

Reply by email

Bernd Oppolzer
to Giuliano Colla: Hi honourable fpc developers! I found a strange error (both with fpc 2.6.4 and fpc 3.0.0,…

Hi Guiliano,

I'm no FPC macro language wizard, but in my believe you are replacing Positiva with False, followed by a semicolon, and so you get the error from the compiler.

{$define Positiva:=False}

should probably work.

HTH,
kind regards

Bernd

Giuliano Colla wrote 31 lines
Hi honourable fpc developers! I found a strange error (both with fpc 2.6.4 and fpc 3.0.0, in Linux environment) The following snippet of code: {$MACRO ON} {$define Positiva:=False;} {$define Negativa:=True;} ....... if HDCOUNT0 >= COUNT0 then V_PIU0 := Positiva else V_PIU0 := Negativa; gives rise to a Fatal: syntax error: ";" expected but "ELSE" found. But if I change the code into: if HDCOUNT0 >= COUNT0 then V_PIU0 := False else V_PIU0 := True; (which IMHO should be identical) it compiles without complaining. Am I doing something wrong or it is a bug? Giuliano _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email

Giuliano Colla
to Bernd Oppolzer: I'm no FPC macro language wizard, but in my believe you are replacing Positiva with…

Il 12/04/2017 19:54, Bernd Oppolzer ha scritto:

Show quoted text 7 lines
I'm no FPC macro language wizard, but in my believe you are replacing Positiva with False, followed by a semicolon, and so you get the error from the compiler. {$define Positiva:=False} should probably work.

You are right, I was misled by some examples in the docs, but reading more carefully, actually it states that the syntax is

{$define ident:=expr}

so that my semicolon is part of the define, and not a termination as I had understood.

Thanks a lot.

Giuliano

Reply by email

Bernd Oppolzer
to Giuliano Colla: Il 12/04/2017 19:51, Michael Van Canneyt ha scritto: Without semicolon it works! Thanks a…

No,

if you put a semicolon in there, you will get wrong syntax, no matter what the datatype is.

Example:

{$MACRO ON}
{$define Fifteen:=15;}
{$define Twelve:=12;}
.......
      if HDCOUNT0 >= COUNT0 then X := Fifteen
       else X := Twelve;

will generate this Pascal statement:

      if HDCOUNT0 >= COUNT0 then X := 15;
       else X := 12;

and the semicolon before the else is wrong in Pascal syntax.

Remember: $define (macro processing) is stupid text replacement ...

HTH,

Bernd

Giuliano Colla wrote 16 lines
Il 12/04/2017 19:51, Michael Van Canneyt ha scritto: > Try removing the semicolon: > {$define Positiva:=False} > {$define Negativa:=True} Without semicolon it works! Thanks a lot. BTW, do you think that this holds true only for the define of boolean values? _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email