int main() {
int sz = 10;
goto end;
char bytes[sz];
end:
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我在编译时遇到以下错误.我使用gcc和C99标准.
test.c: In function ‘main’:
test.c:3:2: error: jump into scope of identifier with variably modified type
test.c:5:1: note: label ‘end’ defined here
test.c:4:7: note: ‘bytes’ declared here
Run Code Online (Sandbox Code Playgroud)
Bri*_*ian 14
标准是禁止的:
Run Code Online (Sandbox Code Playgroud)C99 standard, paragraph 6.8.6.1 Constraints [...] A goto statement shall not jump from outside the scope of an identi?er having a variably modi?ed type to inside the scope of that identi?er.
您goto跳过bytes在运行时分配数组的行.这是不允许的.
你可以bytes用花括号来限制它的范围,把分配放在goto和标签之前,或者根本不使用goto.
更明确地说,一旦bytes分配,你现在"在"范围内.在分配之前,您在范围之外.所以你不能"从范围外跳"到"范围内".
| 归档时间: |
|
| 查看次数: |
334 次 |
| 最近记录: |