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

Comments

  1. David Heffernan I don't know what is the best, I just faces problems when translating from C to Pascal

    Well in fact Delphi stills my favorite language over all, so C++ is wrong :)

    ReplyDelete
  2. 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++.

    ReplyDelete
  3. David 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

Post a Comment