GCC允许使用可变长度初始化数组 [英] GCC allowing arrays to be initialized with variable length
本文介绍了GCC允许使用可变长度初始化数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
GCC编译以下功能
void f(int i)
{
int a[i];
}
我的印象是,您只能初始化具有固定长度的数组.应该编译吗,并且可以按照我的期望做吗?
I was under the impression that you can only initialize arrays with constant length. Is this supposed to compile, and will it do what I expect it to?
推荐答案
C99添加了可变长度数组.然后gcc
将此扩展名添加到c89中,作为带有-std=gnu89
选项的扩展名(默认值为gcc
).
C99 added variable length arrays. And gcc
adds this to c89 as an extension with -std=gnu89
option (the default with gcc
).
在最新的C标准C11中,可变长度数组支持被标记为可选.
In the latest C Standard, C11, variable length arrays support is marked as optional.
这篇关于GCC允许使用可变长度初始化数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文