Forum > General
Undocumented compiler directive ?
440bx:
Just playing around, I came across the fact that {$ifend} seems to be an "undocumented" synonym of "$endif" as the following short program shows:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$APPTYPE CONSOLE} program CompilerDirectives; const AConst = 1; begin { using endif } {$ifdef FPC } {$if AConst = 3} writeln('AConst = ', AConst); {$endif} {$endif} {$ifdef FPC} {$if AConst = 1} writeln('AConst = ONE'); {$endif} {$endif} { using ifend } {$ifdef FPC } {$if AConst = 3} writeln('AConst = ', AConst); {$ifend} {$ifend} {$ifdef FPC} {$if AConst = 1} writeln('AConst = ONE'); {$ifend} {$ifend} readln;end.
Thaddy:
AFAIK it is documented. It is also Delphi compatible.
EDIT
In the latest docs it is not documented. Seems a regression.
The preferred way to close $IF is $IFEND, not $ENDIF, but both can be used.
Order is:
{$IFDEF/$ENDIF} but NOT $IFEND
{$IF/$IFEND} but ALSO $ENDIF
But $ENDIF and $IFEND should be compatible if, and only if {$IF} is used, so plz file a bug against documentation.
MarkMLl:
There's something wrong here. Newly created Lazarus project using trunk:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program Project1; {$mode objfpc}{$H+} uses {$IFDEF UNIX} cthreads, {$ENDIF} Classes { you can add units after this }; beginend.
I'm pretty sure I've always used $endif, going back to Turbo Pascal and before. $ifend is the aberration.
MarkMLl
Thaddy:
--- Quote from: MarkMLl on June 11, 2021, 11:17:46 am ---
I'm pretty sure I've always used $endif, going back to Turbo Pascal and before. $ifend is the aberration.
MarkMLl
--- End quote ---
Turbo pascal doesn't know $IF , Mark.... Only $IFDEF
Also at least D1 and D2 do not know about {$IF}
Defines with conditional expressions like using $IF defined() or declared() were introduced in a later delphi version.
MarkMLl:
--- Quote from: Thaddy on June 11, 2021, 11:23:39 am ---
--- Quote from: MarkMLl on June 11, 2021, 11:17:46 am ---
I'm pretty sure I've always used $endif, going back to Turbo Pascal and before. $ifend is the aberration.
MarkMLl
--- End quote ---
Turbo pascal doesn't know $IF , Mark.... Only $IFDEF
--- End quote ---
Yes, and the standard way of closing conditionals is endif.
MarkMLl
Navigation
[0] Message Index
[#] Next page