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.
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
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
David Heffernan I don't know what is the best, I just faces problems when translating from C to Pascal
ReplyDeleteWell in fact Delphi stills my favorite language over all, so C++ is wrong :)
Paul TOTH So your argument is based on prejudice rather than evidence? I also prefer Delphi to C++, but most of your argument seems to be based on a lack of knowledge of C++.
ReplyDeleteDavid Heffernan I asked that a few times back in the days of Borland Pascal and early Delphi. Main reason was about libraries (including RTL and such) not compiling and cost of making them compile.
ReplyDelete