[fpc-devel] if-then-else expression
Stefan Glienke
sglienke at dsharp.org
Thu Aug 28 13:38:54 CEST 2025
Parameter evaluation order is ub so you cannot rely on that, regardless of inlining.
And even though the intrinsic could behave differently it still looks like a regular function call and also might clash with existing similarly named existing function.
> On 27/08/2025 16:40 CEST Hairy Pixels via fpc-devel <fpc-devel at lists.freepascal.org> wrote:
>
>
> On Aug 26, 2025 at 3:49:43 AM, Nikolay Nikolov via fpc-devel <fpc-devel at lists.freepascal.org> wrote:
> > But they're not 100% compatible, are they? IfThen evaluates both the true and the false parameter, while the 'if' statement doesn't. For example:
> > s := IfThen(b <> 0, a div b, 999)
> > Will raise a division by zero exception, if b is 0, while
> > s := if b <> 0 then a div b else 999
> > won't.
> > Nikolay
>
>
> I think if the call was inlined it wouldn’t but otherwise it would. FPC can’t reliably inline either so you wouldn’t want to risk that. If that’s a concern then IfThen could be an intrinsic. It’s basically just a macro to a if statement with an assignment. Extremely simple thing to implement.
> _______________________________________________
> fpc-devel maillist - fpc-devel at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
More information about the fpc-devel
mailing list