static_assert(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… static_assert(9) β€” like, the kernel API manual, bestie

okay so picture this: it's Kernel API Manual o'clock and we're talking about static_assert(9). no cap, she's that girl.


✨ NAME ✨

static_assert β€” check an integer constant expression at build time πŸ› οΈβœ¨

like… she checks ur math before the code ever even runs. queen behavior.


πŸŽ€ SYNOPSIS πŸŽ€

static_assert (expr , ... );

🌸 ARGUMENTS 🌸

  • expr β€” the expression to be checked πŸ‘€ that's the whole vibe. this is the thing getting vibe-checked at build time.
  • ... β€” variable arguments 🫢 yes bestie, the varargs are just there, doing their little varargs thing.

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so static_assert is literally a wrapper for the C11 _Static_assert, but with a lil macro magic sprinkled on top ✨ β€” the magic exists so the message is optional, and when you don't give one it defaults to the stringification of the tested expression. cute, right? πŸ’…

now, contrary to BUILD_BUG_ON, static_assert can be used at global scope 🌍 β€” which, slay β€” but it requires the expression to be an integer constant expression. and i cannot stress this enough: it is not enough that __builtin_constant_p is true for expr. like, that is not the bar. the bar is an integer constant expression. periodt. πŸ’€

also note the flip, because this is the part that gets people πŸ™ˆ: BUILD_BUG_ON fails the build if the condition is true, while static_assert fails the build if the expression is false. opposite girls! mirrored icons! don't mix them up fr fr 😭

⚠️ warning bestie: get the polarity backwards and ur build will fail for the exact wrong reason. lowkey iconic, highkey painful.

πŸ”₯ SEE ALSO πŸ”₯

go read those too, iykyk πŸ§šπŸ’œ


and that's the whole page, bestie πŸŽ€πŸŒΈ β€” sourced straight from ./tools/include/linux, dated October 2026, with all my love and zero cap πŸ«ΆπŸ’–

πŸ“¦ where this page comes from