我看不懂的是GTY,不是那个数组到底长度到底如何,这是gccint文档里的例子,即使有错误也没关系,关键是GTY怎么解释 irc上, EricFisher让我先不管它,我就先这么看吧 >In ISO C90, you would have to give contents a length of 1, which means >either you waste space or complicate the argument to malloc. > > >https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html#Zero-Length > >在 2014年8月29日 上午9:57,perr <2029352818@xxxxxx> 写道: >> flexible array members 的长度应该是空的,这里给了长度1,即使是gnu扩展的零长数组,长度也该设为0,两种都不符合 >> >> > >------------------ 原始邮件 ------------------ > >发件人: "Kito Cheng"<kito.cheng@xxxxxxxxx>; > >发送时间: 2014年8月29日(星期五) 凌晨0:28 > >收件人: "hellogcc"<hellogcc@xxxxxxxxxxxxx>; > >主题: [hellogcc] Re: [hellogcc] gccint中GTY一个示例,觉得前后矛盾 >> >> keyword: flexible array members >> >>> 2014-08-28 20:27 GMT+08:00 perr <2029352818@xxxxxx>: >>> 位置: https://gcc.gnu.org/onlinedocs/gccint/GTY-Options.html#GTY-Options >>> >>> length ("expression")选项一节的示例如下:(建议搜索定位) >>> >>> struct GTY(()) rtvec_def { >>> int num_elem; /* number of elements */ >>> rtx GTY ((length ("%h.num_elem"))) elem[1]; >>> }; >>> >>> 假如我定义一个结构变量: >>> >>> struct rtvec_def t; >>> >>> 效果应该是,它会根据t.num_elem来构造t.elem, 但现在就是在构造t, >>> t.num_elem都还没构造好呢,即使构造了也是0才对,在这个语句中,构造长度为0的t.elem[]和语义又不符,它的长度至少是1呀. >>> 因为初看gcc代码,碰上这种东西不理解,请见谅 >>> >>>