https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108896
--- Comment #11 from qinzhao at gcc dot gnu.org --- (In reply to Martin Uecker from comment #9) > > https://www.open-std.org/jtc1/sc22/wg14/www/wg14_document_log thanks for the info. > > But we made variably modified types mandatory in C23 to > help with bounds checking and this already works quite > nicely with GCC / Clang: > > https://godbolt.org/z/ddfsdWPMj nice! can you provide a pointer to the section in C23 that made this change? > > > when this variable length concept is extended to global scope, not sure how > > to > > implement the size expression? need some study here. > > Here, we want to use a member of the struct as a size > expression. This could work equally at function and file scope. > But the semantics need to be worked out. I have started to work > on a patch for GCC a couple of weeks ago using PLACEHOLDER_EXPR, > but did not get very far. > > The idea is to evaluate the size expression whenever the member > with the size is accesses. If the size is not set before, this > would be undefined behavior. > > Other languages such as Ada support this, so in principle this > should be a piece of cake. Oh, Ada can support this already? how does Ada implement this? then we can just borrow Ada's implementation idea to implement this in C if this is approved as an GCC extension for C. > > this proposal basically is to extend the VLA concept from function scope to > > global scope. is my understanding correct? > > I would say the idea is to allow size expressions to refer > to member of a struct instead of only automatic variables. > Okay. > > 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? > > I would disallow it. At least at first. It also raises some > questions: For example, one could form a pointer to the inner > struct, and then it is not clear how 'items' could be accessed > anymore. > Okay.