subexpressions evaluation order

我是研究僧i 提交于 2019-12-02 17:32:08

问题


I've looked at SO/IEC 9899:201x under J.1 Unspecified behavior:

"The order in which subexpressions are evaluated and the order in which side effects
take place, except as specified for the function-call (), &&, ||, ?:, and comma
operators (6.5)."

Does this means that in

func1() + func2();

func2() may be preformed before func1(), or even during func1() ?


回答1:


In the current standard (ISO/IEC 9899:1999) there is a sequence point between function calls but the order of evaluation of the operands to + is not specified so func1 may be called before or after func2 but the function calls must not overlap or be interleaved in any way.

This means that each of func1 and func2 can, if desired, interact with some shared data without having that data change under it in an unexpected way.




回答2:


Not during, but sure, either 1 then 2 or 2 then 1.



来源:https://stackoverflow.com/questions/1745497/subexpressions-evaluation-order

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!