On Fri, May 30, 2025 at 11:06:01AM -0700, Kees Cook wrote:
> #define __DEFINE_FLEX(type, name, member, count, trailer...)          \
>         _Static_assert(__builtin_constant_p(count),                   \
>                        "onstack flex array members require compile-time const 
> count"); \
>         union {                                                               
> \
>                 u8 bytes[struct_size_t(type, member, count)];         \
>                 type obj;                                             \
>         } name##_u trailer;                                           \
>         type *name = (type *)&name##_u
> 
> #define _DEFINE_FLEX(type, name, member, count, initializer...)               
> \
>       __DEFINE_FLEX(type, name, member, count, = { .obj = initializer })
> [...]
> Does that look like what you'd want? (Note I didn't actually build this;
> I want to make sure the concept is workable...)

FWIW, this is working as expected: https://godbolt.org/z/P7Go8Tr33

I'll send a proper patch...

-- 
Kees Cook

Reply via email to