Update: It's more complicated than I realised.

Update: It's more complicated than I realised. The compiler will only skip evaluation of arguments if it is sure that there can be no side effects. For instance, for a direct memory read. If the argument invokes a function then it will be evaluated.

So I have created a storm in error. This post is a lot of FUD. Sorry.

---------

Inline functions are not guaranteed to evaluate their arguments exactly once.

This means that the compiler's choice on whether or not to inline a function can change the observable behaviour.

X := IfThen(b, funcWithSideEffect1, funcWithSideEffect2)

Only one of the side effects will be performed if the function is inlined. If the compiler doesn't inline then both are performed.

I consider this a defect of design. Has inlining in Delphi always been this way?

https://stackoverflow.com/questions/46220994/ifthenassignedwidget-widget-description-no-widget-doesnt-crash-should

Comments