空数组不再被允许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:错误:数组大小L-NAME
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 you it is the last member in a structure
struct foo {
int something;
int somethingelse;
char emptyarr[];
};
这篇关于空数组不再被允许GCC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!