When are parameters calculated, when having concatenated call: obj.F1().F2().F3( sin(x) )?

后端 未结 1 1069
南笙
南笙 2021-01-29 00:39

I use the streaming operators (e.g. operator<<(const char*)) for logging. In my unit tests I have a test like the following:

MyLogger oLogger;         


        
相关标签:
1条回答
  • 2021-01-29 01:01

    This is acceptable behaviour, as it is not specified in which order operands to "operator<<" are being evaluated, and TTBOMK gcc often does it in reverse order to get the parameters onto the stack in the right order for the next function call.

    Think of it in terms of a stack machine:

    push "charly"
    push oLogger
    call operator<<
    pop
    push "bar"
    push 10
    call sleep
    push "foo"
    push oLogger
    call operator<<
    call operator<<
    call operator<<
    pop
    
    0 讨论(0)
提交回复
热议问题