函数参数的破坏顺序是什么?

What is the order of destruction of function arguments?(函数参数的破坏顺序是什么?)
本文介绍了函数参数的破坏顺序是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果某个函数 f 带有参数 p_1, ..., p_n 类型为 T_1, ..., T_n 分别用参数 a_1, ..., a_n 调用,其主体以什么顺序抛出异常、完成或返回论据被破坏了吗?为什么?如果可能,请提供对标准的参考.

If some function f with parameters p_1, ..., p_n of types T_1, ..., T_n respectively is called with arguments a_1, ..., a_n and its body throws an exception, finishes or returns, in what order are the arguments destroyed and why? Please provide a reference to the standard, if possible.

我实际上想问一下函数参数",但作为 T.C.Columbo 设法消除了我的困惑,我将把这个问题留给论点,并问 一个关于参数的新问题.请参阅对此问题的评论以了解区别.

I actually wanted to ask about function "parameters", but as T.C. and Columbo managed to clear my confusion, I'm leaving this question be about the arguments and asked a new separate question about the parameters. See the comments on this question for the distinction.

推荐答案

标准未指定函数参数的计算顺序.来自 C++11 标准(在线草案):

The order in which the arguments to a function are evaluated is not specified by the standard. From the C++11 Standard (online draft):

5.2.2 函数调用

8 [ 注意: 后缀表达式和参数表达式的求值都是无序的.参数表达式评估的所有副作用都在函数之前排序输入(见 1.9).——尾注 ]

8 [ Note: The evaluations of the postfix expression and of the argument expressions are all unsequenced relative to one another. All side effects of argument expression evaluations are sequenced before the function is entered (see 1.9). —end note ]

因此,完全取决于实现来决定以什么顺序评估函数的参数.反过来,这意味着参数的构造顺序也取决于实现.

Hence, it is entirely up to an implementation to decide in what order to evaluate the arguments to a function. This, in turn, implies that the order of construction of the arguments is also implementation dependent.

一个合理的实现会以与构造相反的顺序销毁对象.

A sensible implementation would destroy the objects in the reverse order of their construction.

这篇关于函数参数的破坏顺序是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Rising edge interrupt triggering multiple times on STM32 Nucleo(在STM32 Nucleo上多次触发上升沿中断)
How to use va_list correctly in a sequence of wrapper functions calls?(如何在一系列包装函数调用中正确使用 va_list?)
OpenGL Perspective Projection Clipping Polygon with Vertex Outside Frustum = Wrong texture mapping?(OpenGL透视投影裁剪多边形,顶点在视锥外=错误的纹理映射?)
How does one properly deserialize a byte array back into an object in C++?(如何正确地将字节数组反序列化回 C++ 中的对象?)
What free tiniest flash file system could you advice for embedded system?(您可以为嵌入式系统推荐什么免费的最小闪存文件系统?)
Volatile member variables vs. volatile object?(易失性成员变量与易失性对象?)