GCC allowing arrays to be initialized with variable length [duplicate]

耗尽温柔 提交于 2019-12-13 03:54:05

问题


GCC compiles the following function

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?


回答1:


C99 added variable length arrays. And gcc adds this to c89 as an extension with -std=gnu89 option (the default with gcc).

In the latest C Standard, C11, variable length arrays support is marked as optional.




回答2:


VLA's are allowed in C99. GCC extention allows it to compile in C89 mode.



来源:https://stackoverflow.com/questions/19340544/gcc-allowing-arrays-to-be-initialized-with-variable-length

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!