DEFINE_RAW_FLEX(9)
π DEFINE_RAW_FLEX(9) β the Kernel API Manual moment π
okay so bestie, we're in the Kernel API Manual rn and this page is literally about DEFINE_RAW_FLEX β and no, it's not a dance move, it's a macro. let's get into it β¨
πΈ NAME πΈ
DEFINE_RAW_FLEX β defines an on-stack instance of a structure that has a trailing flexible array member, specifically for the case where that member does not have a __counted_by annotation. iykyk π«Ά
π¦ SYNOPSIS π¦
DEFINE_RAW_FLEX (type , name , member , count );
like, that's the whole vibe. four things go in, a whole struct comes out π
π ARGUMENTS π
typeβ the structure type name, and this includes thestructkeyword fr fr, don't forget it.nameβ the name for the variable you're defining. your main character's name, basically πmemberβ the name of the array member.countβ the number of elements in the array, and heads up: it must be a compile-time constant. no runtime shenanigans bestie, none. π«
β DESCRIPTION β
So what it does: it defines a zeroed, on-stack instance of type structure with a trailing flexible array member. zeroed. on-stack. iconic behaviour honestly. β¨
Then you've got your little helper squad for checking sizes at compile time:
- use
__struct_size(name)to get the compile-time size of it afterwards. - use
__member_size(name->member)to get the compile-time size of thenamemembers. - use
STACK_FLEX_ARRAY_SIZE(name, member)to get the compile-time number of elements in the array member.
three little besties, all compile-time, all slay. π§
π₯ SEE ALSO π₯
the kernel file ./include/linux/overflow.h and honestly the whole overflow friend group came through:
check_add_overflow(9), wrapping_add(9), wrapping_assign_add(9), check_sub_overflow(9), wrapping_sub(9), wrapping_assign_sub(9), check_mul_overflow(9), wrapping_mul(9), check_shl_overflow(9), overflows_type(9), range_overflows(9), range_overflows_t(9), range_end_overflows(9), range_end_overflows_t(9), castable_to_type(9), size_mul(9), size_add(9), size_sub(9), array_size(9), array3_size(9), flex_array_size(9), struct_size(9), struct_size_t(9), struct_offset(9), __DEFINE_FLEX(9), _DEFINE_FLEX(9), DEFINE_FLEX(9), STACK_FLEX_ARRAY_SIZE(9), typeof_flex_counter(9), overflows_flex_counter_type(9), __set_flex_counter(9)
like, the whole group chat. go say hi. ππ
ngl that's the entire page. no cap, no filler, nothing hidden. π
okay so final sign-off: this lil page lives at ./include/linux and it's dated October 2026 β yes, from the future, don't ask. periodt. ππβ
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms