On Tue, 2 Sep 2025 14:37:40 +0200 "Gustavo A. R. Silva" <[email protected]> wrote:
> On 9/2/25 13:17, Michal Koutný wrote: > > On Tue, Sep 02, 2025 at 09:56:34AM +0200, "Gustavo A. R. Silva" > > <[email protected]> wrote: ... > > > > (You seem to be well versed with flex arrays, I was wondering if > > something like this could be rearranged to make it work (assuming the > > union is at the end of its containers): > > > > union { > > struct cgroup *ancestors[]; > > struct { > > struct cgroup *_root_ancestor; > > struct cgroup *_low_ancestors[]; > > }; > > }; > > ) > > Yep, that works (as long as it's always at the very end of any container > or ends last in any nested structs, for instance in struct cgroup_root, > it must also be at the end) for GCC-15+, but for older versions of GCC we > have to use the DECLARE_FLEX_ARRAY() helper as below: Could the warning be disabled for 'older versions of gcc'? A build time warning doesn't need to happen for all builds. David > > union { > /* All ancestors including self */ > DECLARE_FLEX_ARRAY(struct cgroup *, ancestors); > struct { > struct cgroup *_root_ancestor; > struct cgroup *_low_ancestors[]; > }; > }; > > Thanks > -Gustavo >
