什么是函数参数破坏的秩序? [英] What is the order of destruction of function arguments?

查看:112
本文介绍了什么是函数参数破坏的秩序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果某些功能˚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。和科伦坡设法清除我的困惑,我要离开这个问题是大致参数和要求有关参数的一个新的单独的问题。见在这个问题上的区别的意见。

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的注意:的后缀前pression和论证前pressions的评价都是相对彼此unsequenced。参数前pression评估的所有副作用函数之前测序
  进入(见图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.

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

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