gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 16:29:40 26 4
gpt4 key购买 nike

int a=1, b=a++; 是否调用未定义的行为? a 的初始化和它在 b 的初始化器中的访问和修改之间没有序列点介入,但据我所知,初始化不是“修改”对象的;指定了一个初始化器来给出对象的“初始值”。根据 6.7.8 初始化,第 8 段:

An initializer specifies the initial value stored in an object.

并且在对对象进行任何访问之前将“初始”作为排序似乎是合理的。以前是否考虑过这个问题,是否有公认的解释?

最佳答案

它不会调用未定义的行为。 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.

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

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

关于c - int a=1, b=a++;调用未定义的行为?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16219082/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com