View Issue Details

IDProjectCategoryView StatusLast Update
0038492FPCCompilerpublic2021-05-13 22:00
ReporterAdriaan van Os Assigned ToJonas Maebe  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version3.2.0 
Fixed in Version3.3.1 
Summary0038492: $setc regression
Descriptionadriaan% cat setcbug.pas

{$mode macpas}
{$setc def := mydefine}
program setcbug;
begin
{$ifc def}
  writeln( 'mydefine is true')
{$elsec}
  writeln( 'mydefine is false')
{$endc}
end.

adriaan% /usr/local/lib/fpc/3.0.4/ppc386 setcbug -Sm -dmydefine:=false
Free Pascal Compiler version 3.0.4 [2017/11/26] for i386
Copyright (c) 1993-2017 by Florian Klaempfl and others
Target OS: Darwin for i386
Compiling setcbug.pas
Assembling (pipe) setcbug.s
Linking setcbug
11 lines compiled, 0.1 sec

adriaan% /usr/local/lib/fpc/3.2.0/ppc386 setcbug -Sm -dmydefine:=false
Free Pascal Compiler version 3.2.0 [2020/05/31] for i386
Copyright (c) 1993-2020 by Florian Klaempfl and others
Target OS: Darwin for i386
Compiling setcbug.pas
setcbug.pas(3,2) Error: Compile time expression: Wanted Boolean, Integer but got AnsiString at SETC
setcbug.pas(12) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted

In other words, $setc doesn't work anymore with 3,2.0, where it did with 3.0.4.
TagsNo tags attached.
Fixed in Revision38492
FPCOldBugId
FPCTarget-
Attached Files

Activities

Adriaan van Os

2021-02-15 18:42

developer   ~0128942

Things are even worse than I thought.

{$mode macpas}
program setcbug2;
begin
{$ifc mydefine}
  writeln( 'mydefine is true')
{$elsec}
  writeln( 'mydefine is false')
{$endc}
end.

adriaan% /usr/local/lib/fpc/3.0.4/ppc386 setcbug2 -Sm -dmydefine:=false
Free Pascal Compiler version 3.0.4 [2017/11/26] for i386
Copyright (c) 1993-2017 by Florian Klaempfl and others
Target OS: Darwin for i386
Compiling setcbug2.pas
Assembling (pipe) setcbug2.s
Linking setcbug2
10 lines compiled, 0.1 sec

adriaan% /usr/local/lib/fpc/3.2.0/ppc386 setcbug2 -Sm -dmydefine:=false
Free Pascal Compiler version 3.2.0 [2020/05/31] for i386
Copyright (c) 1993-2020 by Florian Klaempfl and others
Target OS: Darwin for i386
Compiling setcbug2.pas
setcbug2.pas(5,6) Error: Compile time expression: Wanted Boolean but got AnsiString at IF or ELSEIF
setcbug2.pas(11) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted

Jonas Maebe

2021-02-17 14:35

manager   ~0128975

The common universal interfaces use the construct {$ifc defined XXX and XXX} everywhere instead (and have always done so afaik). Is that then technically superfluous? Even your own page on porting to GPC uses the "defined" check: http://www.microbizz.nl/gpcdiffs.html (under "Conditional compiler directives").

Personally, I prefer being explicit about whether you're checking whether something is defined, or whether it's defined as having a boolean true/false value. The above preprocessor checks read like C-style if-statements. That doesn't mean we shouldn't fix it, of course.

Adriaan van Os

2021-02-17 15:06

developer   ~0128976

I have always strongly preferred the false/true test over the defined test. With the defined test, if you misspell the name or simply forget it, the defined test translates that omission into value "false". With $setc that can not happen, because if the value is not defined to be true or false, you get an error.

Think about the word "defined". Something is not defined, but we act as if it is defined with value false. That is one of the strange C-habits that are common but completely nuts if you think about it rationally.

And indeed, gpc didn't have $setc when I wrote that webpage.

Adriaan van Os

2021-02-17 15:08

developer   ~0128977

This is even the reason that I feel not-at-ease with other fpc dialects than macpascal. I shiver when I see (or have to use) "defined".

Jonas Maebe

2021-02-17 15:25

manager   ~0128978

> With $setc that can not happen, because if the value is not defined to be true or false, you get an error.

I don't understand. In your second test program, the one in the first comment, FPC 3.0.4 does not give an error, but FPC 3.2.0 does. And "mydefine" is not defined as anything. But given your comment "Things are even worse than I thought.", I understood that FPC 3.0.4's behaviour is actually the desired one? Yet here you say you should get an error if it's not defined.

Adriaan van Os

2021-02-17 16:20

developer   ~0128979

Look at the command-line of the second test-program (in my first comment). It does set -dmydefine:=false. So it is defined with value false. You could just as well set -dmydefine:=true on the command-line and then you get another output with fpc-3.0.4 and fpc-3.2.0 still gives an error.

And yes, if I forget -dmydefine:=false or -dmydefine:=true on the command-line, an error from the compiller is what I should get and that is what fpc-3.0.4 perfectly well does

adriaan% /usr/local/lib/fpc/3.0.4/ppc386 setcbug2 -Sm
Free Pascal Compiler version 3.0.4 [2018/09/30] for i386
Copyright (c) 1993-2017 by Florian Klaempfl and others
Target OS: Darwin for i386
Compiling setcbug2.pas
setcbug2.pas(5,6) Error: Compile time variable or macro "MYDEFINE" is not defined.
setcbug2.pas(5,6) Error: Compile time expression: Wanted Boolean but got AnsiString at IF or ELSEIF
setcbug2.pas(11) Fatal: There were 2 errors compiling module, stopping
Fatal: Compilation aborted

adriaan% /usr/local/lib/fpc/3.0.4/ppc386 setcbug2 -Sm -dmydefine:=false
Free Pascal Compiler version 3.0.4 [2018/09/30] for i386
Copyright (c) 1993-2017 by Florian Klaempfl and others
Target OS: Darwin for i386
Compiling setcbug2.pas
Assembling (pipe) setcbug2.s
Linking setcbug2
10 lines compiled, 0.2 sec

adriaan% ./setcbug2
mydefine is false

adriaan% /usr/local/lib/fpc/3.0.4/ppc386 setcbug2 -Sm -dmydefine:=true
Free Pascal Compiler version 3.0.4 [2018/09/30] for i386
Copyright (c) 1993-2017 by Florian Klaempfl and others
Target OS: Darwin for i386
Compiling setcbug2.pas
Assembling (pipe) setcbug2.s
Linking setcbug2
10 lines compiled, 0.1 sec

adriaan% ./setcbug2
mydefine is true

Well OK, maybe in this context the compiler-variable name "mydefine" is confusing. Replace it with mycompilervar.

Adriaan van Os

2021-02-17 16:22

developer   ~0128980

Note that the regression doesn't occur if -Sm is omitted on the command-line.

Adriaan van Os

2021-02-17 18:12

developer   ~0128981

Think of a programming language where you declare var b:boolean which then means that it gets value True. If you want it to have value False, you simply don't declare it. Isn't that completely idiotic ?

Yes, but in another context, we are used to it and find it normal .....

Jonas Maebe

2021-02-17 18:59

manager   ~0128982

I indeed missed the definition of the macro on the command line. I actually missed that for both programs. As a result, you misunderstood my argument. I was not arguing that using {$ifc defined xxx} is somehow better than {$ifc xxx}. I thought that you were saying that

{$setc def := mydefine}
{$ifc def}
..
{$endc}

should successfully compile, because "def" was defined. As mentioned, I missed the fact that you defined "mydefine" on the command line as "false".

Adriaan van Os

2021-02-17 20:11

developer   ~0128984

OK

Jonas Maebe

2021-04-10 12:57

manager   ~0130222

I'm not sure why it worked in 3.0.4, because the code I fixed was broken there too. Perhaps it worked nevertheless due to another bug that masked this one.

Adriaan van Os

2021-05-13 22:00

developer   ~0130860

OK, thanks.

Issue History

Date Modified Username Field Change
2021-02-15 18:29 Adriaan van Os New Issue
2021-02-15 18:42 Adriaan van Os Note Added: 0128942
2021-02-17 14:35 Jonas Maebe Note Added: 0128975
2021-02-17 15:06 Adriaan van Os Note Added: 0128976
2021-02-17 15:08 Adriaan van Os Note Added: 0128977
2021-02-17 15:25 Jonas Maebe Note Added: 0128978
2021-02-17 16:20 Adriaan van Os Note Added: 0128979
2021-02-17 16:22 Adriaan van Os Note Added: 0128980
2021-02-17 18:12 Adriaan van Os Note Added: 0128981
2021-02-17 18:59 Jonas Maebe Note Added: 0128982
2021-02-17 20:11 Adriaan van Os Note Added: 0128984
2021-04-10 12:57 Jonas Maebe Assigned To => Jonas Maebe
2021-04-10 12:57 Jonas Maebe Status new => resolved
2021-04-10 12:57 Jonas Maebe Resolution open => fixed
2021-04-10 12:57 Jonas Maebe Fixed in Version => 3.3.1
2021-04-10 12:57 Jonas Maebe Fixed in Revision => 38492
2021-04-10 12:57 Jonas Maebe FPCTarget => -
2021-04-10 12:57 Jonas Maebe Note Added: 0130222
2021-05-13 22:00 Adriaan van Os Status resolved => closed
2021-05-13 22:00 Adriaan van Os Note Added: 0130860