__flex_counter(9)
π
__flex_counter π
okay so this is a kernel API manual page, from the <pink>Kernel API Manual</pink> girlies, and today's main character is __flex_counter β the little helper that grabs you a pointer to the counter member of a flexible array, but only if somebody was cute enough to annotate it with __counted_by(). iykyk π
β¨ NAME β¨
__flex_counter β get a pointer to the counter member of the given flexible array, if it was annotated with __counted_by() πΈ
β¨ SYNOPSIS β¨
__flex_counter (FAM );
β¨ ARGUMENTS β¨
FAMβ pointer to the flexible array member of an addressable struct instance, bestie. that's the whole vibe. π¦
β¨ DESCRIPTION β¨
okay so picture this, right? you've got something like:
struct foo { int counter; short array[] __counted_by(counter); } *p;
and then __flex_counter(p->array) will literally resolve to p->counter. slay. it's giving "find the counter, no cap." π
β οΈ heads up though: Clang may not allow this to be assigned to a separate variable β it must be used directly. not me finding that out the hard way π so don't try to stash it in a local and go about your day, fr fr.
and if p->array is unannotated? it returns (void *)NULL. that's it. that's the whole story. π no annotation, no counter, no nothing. vibe check failed, respectfully. π
β¨ SEE ALSO β¨
- Kernel file
./include/linux/compiler_types.h compiletime_assert(9)β
and that's the page, bestie! π«Ά this one lives in ./include/linux, dated October 2026 β mwah, go annotate your flexible arrays, ily ππ§β¨
π¦ 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