订货在C,C初始化++ [英] Ordering in an initialization in C, C++

查看:104
本文介绍了订货在C,C初始化++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下初始化:

/* C, C++ */
int a[] = { f(), g() };
struct { int x, y } foo = { f(), g() };

/* C++ */
struct goo { goo(int x, int y);  };

goo b = { f(), g() };
goo c { f(), g() };    /* C++11 */
goo d ( f(), g() );

时的顺序执行 F()克()由C和C ++标准中规定的任何行?

Is the order of execution f() and g() in any line specified by C and C++ standards?

推荐答案

在所有这两种情况下

goo b = { f(), g() };
goo c { f(), g() };    /* C++11 */

从左至右和所有副作用应在下一个初始化之前施加评价的顺序确定

the order of evaluation is determined from left to right and all side effects shall be applied before the next initializer.

从C ++标准

4在一个支撑-INIT-列表的初始化列表,该
  初始化从句,包括任何由包扩张导致
  (14.5.3),在它们出现的顺序进行评估。那是,
  与给定的相关联的每一个值的计算和副作用
  每个值计算之前初始化从句被测序
  副作用与它后面的任何初始化,相关条款
  用逗号分隔的初始化列表清单。

4 Within the initializer-list of a braced-init-list, the initializer-clauses, including any that result from pack expansions (14.5.3), are evaluated in the order in which they appear. That is, every value computation and side effect associated with a given initializer-clause is sequenced before every value computation and side effect associated with any initializer-clause that follows it in the comma-separated list of the initializer-list.

但是用C还有其他规则

初​​始化列表前pressions的评价是
  相对于indeterminately测序以彼此并且因此
  其中出现的任何副作用顺序是不确定的。

The evaluations of the initialization list expressions are indeterminately sequenced with respect to one another and thus the order in which any side effects occur is unspecified.

这篇关于订货在C,C初始化++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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