简体   繁体   English

int a = 1,b = a ++; 调用未定义的行为?

[英]Does int a=1, b=a++; invoke undefined behavior?

Does int a=1, b=a++; 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; 还有就是初始化介于其间没有顺序点a和在初始化的访问和修改b ,但据我所知,初始化是不是对象的“修改”; an initializer is specified to give the "initial value" of the object. 指定初始值设定项以提供对象的“初始值”。 Per 6.7.8 Initialization, paragraph 8: 根据6.7.8初始化,第8段:

An initializer specifies the initial value stored in an object. 初始值设定项指定存储在对象中的初始值。

and it seems reasonable to take "initial" as being sequenced before any access to the object. 在对对象进行任何访问之前,将“initial”作为顺序进行似乎是合理的。 Has this issue been considered before, and is there an accepted interpretation? 此问题是否已经考虑过,是否有可接受的解释?

It doesn't invoke undefined behaviour. 它不会调用未定义的行为。 In 6.7.6 (3), it is stated 在6.7.6(3)中,陈述

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 释放分配给char *的int *(由`malloc`分配)是否会调用Undefined Behavior? - Does freeing an int* which was assigned to a char* (allocated by `malloc`) invoke Undefined Behavior? 在溢出的情况下,i ++是否为小于int的签名类型调用未定义的行为? - Does i++ invoke undefined behavior for signed types smaller than int in case of overflow? 语句'int val =(++ i> ++ j)吗? ++ i:++ j;`调用未定义的行为? - Does the statement `int val = (++i > ++j) ? ++i : ++j;` invoke undefined behavior? 这会使用C中的链接调用未定义的行为吗? - Does this invoke undefined behavior with linkage in C? printf("%x",1) 是否调用未定义的行为? - Does printf(“%x”,1) invoke undefined behavior? 这种滥用函数声明是否会调用未定义的行为? - Does this abuse of function declarations invoke undefined behavior? INT_MIN%-1是否会产生未定义的行为? - Does INT_MIN % -1 produce undefined behavior? *a++ = *b++(这是什么意思,它是如何工作的) - *a++ = *b++ (what does it mean, how it works) 动态数组的惯用初始化是否会调用未定义的行为? - Does idiomatic initialization of a dynamic array invoke Undefined Behavior? 在没有适当原型的情况下调用 printf 是否会调用未定义的行为? - Does calling printf without a proper prototype invoke undefined behavior?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM