https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108896
--- Comment #8 from qinzhao at gcc dot gnu.org --- (In reply to Martin Uecker from comment #7) > An attribute is certainly simpler and should be easy to add. yes. > > I proposed similar extension for C23 and there was some interest, > but I did not have time to follow up. > > https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2660.pdf very interesting proposal! are there any discussions on this proposal? if so, can you point me to them? > > > Sizeof is not a constant expression in ISO C for a VLA and it is not a > constant expression if the struct contains a VLA (GNU extension). So this > is already the case and nothing would need to change. It would also > potentially > avoid mistakes when computing the size of such a struct. agreed. However, my understanding is: VLA is only valid inside a function scope. GCC use a special SAVE_EXPR to record its size expression. and evaluated during runtime only once. when this variable length concept is extended to global scope, not sure how to implement the size expression? need some study here. > But the > rules for initialization are not so clear. shall we make this clear? > > I do not think it is a good idea to differentiate between file scope structs > and others. This would be confusing. Yes. agreed. this proposal basically is to extend the VLA concept from function scope to global scope. is my understanding correct? > > Considering that the GNU extensions is rarely used, one could consider > redefining the meaning of > > int n = 1; > struct { > int n; > char buf[n]; > }; > > so that the 'n' refers to the member. Or we add a new syntax similar to > designators (which intuitively makes sense to me). designator might be better IMO. a question here is: for the following nested structure: struct object { ... char items; ... struct inner { ... int flex[]; }; } *ptr; what kind of syntax is good to represent the upper bound of "flex" in the inner struct with "items" in the outer structure? any suggestion?