[fpc-pascal] New feature: IfThen() intrinsic

Marco van de Voort marcov at stack.nl
Mon Feb 1 08:59:00 CET 2016


In our previous episode, Sven Barth said:
> After the discussion last year about the inline-if I've decided to add
> it as an intrinsic function instead of an extension of the language.
> Like all intrinsics it's part of the System unit and "declared" like this:
> 
> === code begin ===
> 
> function IfThen(Condition: Boolean; ThenExpr, ElseExpr: type): type;
> 
> === code end ===
> 
> Since it's declared in the System unit it won't interfere with the
> IfThen()s that are declared in the Math unit or other units, so they'll
> continue to work as before to avoid any surprises.
> 
> An important point to note is that in general the result type is
> determined by the ThenExpr (there are a few usability exceptions
> regarding strings and chars).

I'm not really fond of the functionality, and I would not write new code
with it, but it is very handy when converting C code.
 
The only really bad thing is the name, as Florian already said, with the
versions in strutils and math.  The clash with delphi compatible functions
should be avoided.



More information about the fpc-pascal mailing list