BUILD_BUG_ON(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… BUILD_BUG_ON(9) πŸ’…

okay so bestie, welcome to the Kernel API Manual β€” this page is literally about making the compiler catch your vibes at build time, not runtime. no cap. ✨

πŸŽ€ NAME πŸŽ€

BUILD_BUG_ON β€” break compile if a condition is true. periodt. πŸ’₯

🌸 SYNOPSIS 🌸

BUILD_BUG_ON (condition );

πŸ¦‹ ARGUMENTS πŸ¦‹

  • condition β€” the condition which the compiler should know is false. like, it has to be something the compiler can actually clock at compile time, bestie. πŸ‘€

πŸ’– DESCRIPTION πŸ’–

so here's the tea: if you have some code which relies on certain constants being equal, or some other compile-time-evaluated condition, you should use BUILD_BUG_ON to detect if someone changes it. it's giving β€œguardrail for your constants,” and honestly? iconic. πŸ›‘οΈβœ¨

like, not me trusting everyone to leave your compile-time assumptions alone β€” BUILD_BUG_ON is right there to catch it when somebody messes with them. πŸ’…

πŸ”₯ SEE ALSO πŸ”₯

also check out the kernel file ./tools/include/linux/build_bug.h, plus BUILD_BUG_ON_MSG(9), BUILD_BUG(9), and static_assert(9). iykyk 🫢


this page is from ./tools/include/linux, dated October 2026, and it's the BUILD_BUG_ON(9) manual page β€” mwah πŸ’‹πŸŒΈ

πŸ“¦ where this page comes from