static_assert(9)
π 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 π₯
- Kernel file
./tools/include/linux/build_bug.hπ BUILD_BUG_ON_MSG(9)BUILD_BUG_ON(9)BUILD_BUG(9)
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
- 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