View Issue Details

IDProjectCategoryView StatusLast Update
0034858FPCCompilerpublic2019-03-17 16:21
Reporteruser5570Assigned ToJonas Maebe 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product VersionProduct Build 
Target VersionFixed in Version3.3.1 
Summary0034858: Conditional compilations fails: {$ifdef} {$elseif} {$endif}
Description{$IFDEF ENDIAN_LITTLE}
//
{$ELSEIF ENDIAN_BIG}
//
{$ELSE}
  {$ERROR Unknown endian}
{$ENDIF}

Documentation state this should be correct syntax:
https://www.freepascal.org/docs-html/prog/progsu14.html#x21-200001.2.14

However, error: "ENDIF without IF(N)DEF" is shown due compilation on line with $ELSEIF.
Steps To ReproduceCreate new app and place upper code anywhere and try to compile.
TagsNo tags attached.
Fixed in Revision41724
FPCOldBugId
FPCTarget
Attached Files

Activities

Serge Anvarov

2019-01-13 09:37

reporter   ~0113370

As far as I understand, the documentation says {$ELSEIF ...} can only be applied to {$IF ...}, not the {$IFDEF ...} you are using.

user5570

2019-01-13 10:12

  ~0113371

Thank you Sergey,

I assume can be used defined() with $IF, however Delphi have supported $IFDEF with $ELSEIF and $IFEND (instead $ENDIF), which is definitely simpler and clearer. FPC seems do not support it, yet.

http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/devcommon/compdirselseifdirective_xml.html

J. Gareth Moreton

2019-01-13 16:39

developer   ~0113382

I can confirm that $ELSEIF belongs to the $IF and $IFEND family. If you want to build something akin to what you specified, you need to write the following:

{$IFDEF ENDIAN_LITTLE}
...
{$ELSE} // Adding ENDIAN_LITTLE afterwards is optional
  {$IFDEF ENDIAN_BIG}
  ...
  {$ELSE}
    {$ERROR Unknown endian}
  {$ENDIF}
{$ENDIF}

Alternatively, you can do:

{$IF defined(ENDIAN_LITTLE)}
...
{$ELSEIF defined(ENDIAN_BIG)}
...
{$ELSE}
  {$ERROR Unknown endian}
{$IFEND}

Regardless, the documentation and the Delphi support you mention may need to be evaluated.

Issue History

Date Modified Username Field Change
2019-01-13 04:54 user5570 New Issue
2019-01-13 09:37 Serge Anvarov Note Added: 0113370
2019-01-13 10:12 user5570 Note Added: 0113371
2019-01-13 11:01 Michael Van Canneyt Project Lazarus => FPC
2019-01-13 16:39 J. Gareth Moreton Note Added: 0113382
2019-03-16 22:38 Jonas Maebe Fixed in Revision => 34858
2019-03-16 22:38 Jonas Maebe Status new => resolved
2019-03-16 22:38 Jonas Maebe Fixed in Version => 3.3.1
2019-03-16 22:38 Jonas Maebe Resolution open => fixed
2019-03-16 22:38 Jonas Maebe Assigned To => Jonas Maebe
2019-03-17 16:21 Jonas Maebe Fixed in Revision 34858 => 41724
2019-03-17 16:21 Jonas Maebe Product Version 2.0RC3 =>
2019-03-17 16:21 Jonas Maebe Description Updated View Revisions