Compilers and argument order of evaluation in C++

前端 未结 6 532
一整个雨季
一整个雨季 2020-11-22 10:33

Okay, I\'m aware that the standard dictates that a C++ implementation may choose in which order arguments of a function are evaluated, but are there any implementations that

6条回答
  •  粉色の甜心
    2020-11-22 11:23

    Read this

    It's not an exact copy of your question, but my answer (and a few others) cover your question as well.

    There are very good optimization reasons why the compiler might not just choose right-to-left but also interleave them.

    The standard doesn't even guarantee a sequential ordering. It only guarantees that when the function gets called, all arguments have been fully evaluated.

    And yes, I have seen a few versions of GCC do exactly this. For your example, foo(0,0) would be called, and i would be 2 afterwards. (I can't give you the exact version number of the compiler. It was a while ago - but I wouldn't be surprised to see this behavior pop up again. It's an efficient way to schedule instructions)

提交回复
热议问题