【发布时间】:2016-10-27 13:39:49
【问题描述】:
最小代码示例:
#include <stdio.h>
int main()
{
const int a = 5;
static int b[a];
return 0;
}
看起来不错,嗯?变量a 是常量。也适用于 4.4。
gcc -v
gcc version 6.2.1 20160830 (GCC)
gcc 1.c
1.c: In function ‘main’:
1.c:6:16: error: storage size of ‘b’ isn’t constant
static int b[a];
顺便说一句,clang 很好地编译了这段代码。
【问题讨论】:
-
只是想知道为什么这不被视为 VLA...
-
@SouravGhosh 因为
static。 -
它在https://gcc.godbolt.org/ 上使用 gcc 和 clang 编译得很好。
-
@MichaelWalz:试试
-Werror=pedantic,编译会失败。这不是一个符合标准的 C 程序。 -
@MichaelWalz:现在这是一个 GCC 错误。