__flex_counter(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… __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 ✨


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