gpt4 book ai didi

c - 转到 VLA 范围

转载 作者:行者123 更新时间:2023-12-02 06:51:43 24 4
gpt4 key购买 nike

这是允许的吗?

goto inside;
{
inside:
int a[n];
}

A goto statement shall not jump from outside the scope of an identifier having a variably modified type to inside the scope of that identifier.

反过来呢?

{
goto outside;
int a[n];
}
outside: ;

{
int a[n];
goto outside;
}
outside: ;

它们是一回事吗?

最佳答案

第一个是不允许的,原因是你不能将标签应用于声明。

标签位于 VLA 的范围之前,如果有可执行代码(正式地,一个语句;即使是空的也可以)来标记,那么你就可以了:

goto inside;
{
inside:;
int a[n]; // Scope of a starts here!
}

两个 goto outside 片段都很好。


评论中讨论了标识符的范围,以及数组 a[n] 何时进入范围。标准(C99 和 C11 — 在相同的部分编号中)说:

6.2.1 Scopes of identifiers

¶7 Structure, union, and enumeration tags have scope that begins just after the appearance ofthe tag in a type specifier that declares the tag. Each enumeration constant has scope thatbegins just after the appearance of its defining enumerator in an enumerator list. Anyother identifier has scope that begins just after the completion of its declarator.

在C90标准的§6.1.2.1中,但写法是一样的。

关于c - 转到 VLA 范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42358542/

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