BUILD_BUG_ON(9)

BUILD_BUG_ON9

Break compile if a condition is true.

Usage

BUILD_BUG_ON(condition);

Arguments

condition

the condition which the compiler should know is false.

Overview

If you have some code which relies on certain constants being equal, or other compile-time-evaluated condition, you should use BUILD_BUG_ON to detect if someone changes it.

The implementation uses gcc's reluctance to create a negative array, but gcc (as of 4.4) only emits that error for obvious cases (eg. not arguments to inline functions). So as a fallback we use the optimizer; if it can't prove the condition is false, it will cause a link error on the undefined “__build_bug_on_failed”. This error message can be harder to track down though, hence the two different methods.

From linux-manual-3.2 3.2.78-1 in Debian 7 (Wheezy). Parsed by carta from the page's man source.