嵌套函数调用的求值顺序 [英] Nested function calls order of evaluation

查看:156
本文介绍了嵌套函数调用的求值顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

众所周知,未指定的函数参数的求值顺序可能因不同的编译器而异。

It's well-known that the order of evaluation of a function's arguments in unspecified and can differ between different compilers.

什么似乎不清楚是函数调用可以在以下意义上交织:

What doesn't seem so clear is whether function calls can be interleaved, in the following sense:

f(g(h()), i(j()))

让我们假设编译器首先选择评估f的第一个参数。是编译器在调用 h g j >?我相信所以,但我不知道在标准中找到确认。

Let's assume the compiler chooses to evaluate f's first parameter first. Is the compiler free to call j between calling h and g? I believe so, but I don't know where to find confirmation in the Standard.

推荐答案

评估顺序未指定 - 见标准的第5.2.2 / 8节:

The evaluation order is unspecified - see section 5.2.2/8 of the Standard:


参数
的求值顺序未指定。
参数表达式求值的所有副作用在输入函数之前需要
效果。

The order of evaluation of arguments is unspecified. All side effects of argument expression evaluations take effect before the function is entered.

这篇关于嵌套函数调用的求值顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆