gcc不再允许空数组吗? [英] Are empty arrays no longer allowed by gcc?
问题描述
我有 gcc 4.7.2-3,我收到以下错误:
I have gcc 4.7.2-3 and I get this following error:
main.c:5:6: 错误:fname"中缺少数组大小
main.c:5:6: error: array size missing in ‘fname’
main.c:6:6: 错误:lname"中缺少数组大小
main.c:6:6: error: array size missing in ‘lname’
初始化时:
int fname[];
int lname[];
使用更高版本的 gcc 是否不再可能?因为我确定我以前用过这个……
Is this no longer possible using higher versions of gcc? Because I am certain I have used this before...
我之所以说我记得这一点,是因为我什至在这里看到它:http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/V40F_HTML/AQTLTBTE/DOCU_046.HTM
The reason I say I remember this, is because I even see it here: http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/V40F_HTML/AQTLTBTE/DOCU_046.HTM
推荐答案
只有马上初始化才能声明一个没有大小的数组
You can only declare an array with no size if you are initializing it right away
int myarr[] = {1, 2, 3};
或者如果它是结构中的最后一个成员
or if it is the last member in a structure
struct foo {
int something;
int somethingelse;
char emptyarr[];
};
这篇关于gcc不再允许空数组吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!