Discussion:
Compiler bug in macro handling?
(too old to reply)
Giuliano Colla
2017-04-12 17:39:41 UTC
Permalink
Raw Message
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 - fpc-***@lists.freepascal.org
http://lists.freepascal.org/c
Michael Van Canneyt
2017-04-12 17:51:27 UTC
Permalink
Raw Message
Post by 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)
{$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.
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.
_______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailma
Giuliano Colla
2017-04-12 18:11:09 UTC
Permalink
Raw Message
Post by Michael Van Canneyt
{$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 - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-b
Bernd Oppolzer
2017-04-12 18:26:58 UTC
Permalink
Raw Message
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
Post by Giuliano Colla
Post by Michael Van Canneyt
{$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?
_______________________________________________
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
_______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/

Bernd Oppolzer
2017-04-12 17:54:50 UTC
Permalink
Raw Message
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
Post by 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)
{$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.
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
_______________________________________________
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
_______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-
Giuliano Colla
2017-04-12 18:19:45 UTC
Permalink
Raw Message
Post by Bernd Oppolzer
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


_______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/lis
Loading...