可以重新排序函数调用 [英] Can function calls be reordered

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

问题描述

我使用C ++ 98。函数调用在什么程度上可以重新排序?我不使用任何全局状态,只有状态对象的本地函数。

I am using C++98. To what extent can function calls be reordered? I am not using any global state, only state of objects local to the function.

我的具体情况是:

{
  RaiiType T;
  Object1.FunctionCall();
  Object2.FunctionCall();
}

其中Object1和Object2在下一个范围中声明。是允许 T 的构造函数在函数调用之后重新排序,假设它可以被简单地证明(至少对于人类),在构造和函数调用?

Where Object1 and Object2 are declared in the next scope up. Is the constructor for T permitted to be reordered after either function call, assuming that it can be trivially proven (at least to a human) that there are no dependencies between the construction and the function calls?

在我特定的情况下,RAII对象用于计算函数调用的执行时间。 / p>

In my particular case, the RAII object is used to time the execution of the function calls.

推荐答案

只要符合标准的程序无法区分其

So long as a standards-compliant program could not tell the difference in its observable behavior, the compiler (as well as other components in the system) may freely reorder instructions and operations however it likes.

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

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