难道诠释A = 1,B = A ++;未定义行为? [英] Does int a=1, b=a++; invoke undefined behavior?

查看:147
本文介绍了难道诠释A = 1,B = A ++;未定义行为?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

确实 INT A = 1,B = A ++; 未定义行为?还有就是初始化之间中间没有顺序点 A 及其访问和修改在初始化为 B ,但作为据我所知,初始化是不是对象修改;一个初始被指定给对象的初始值。每6.7.8初始化,第8段:

Does int a=1, b=a++; invoke undefined behavior? There is no sequence point intervening between the initialization of a and its access and modification in the initializer for b, but as far as I can tell, initialization is not "modification" of the object; an initializer is specified to give the "initial value" of the object. Per 6.7.8 Initialization, paragraph 8:

这是初始化指定存储在对象的初始值。

An initializer specifies the initial value stored in an object.

和似乎是合理的采取初始像以前一样对对象的任何访问被测序。有这个问题之前已经考虑,而且有一个公认的跨pretation?

and it seems reasonable to take "initial" as being sequenced before any access to the object. Has this issue been considered before, and is there an accepted interpretation?

推荐答案

它不会调用未定义的行为。在6.7.6(3)中,记载

It doesn't invoke undefined behaviour. In 6.7.6 (3), it is stated

一个完整的声明符是一个声明符,是不是另一种说明符的一部分。一个完整的结束
  声明符是一个序列点。

A full declarator is a declarator that is not part of another declarator. The end of a full declarator is a sequence point.

这是一个完整的声明符的末尾是一个序列点。

that the end of a full declarator is a sequence point.

int a = 1, b = a++;
     //  ^ end of full declarator

这篇关于难道诠释A = 1,B = A ++;未定义行为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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