Name

BUILD_BUG_ON — break compile if a condition is true.

Synopsis

BUILD_BUG_ON ( condition);
 

Arguments

condition

the condition which the compiler should know is false.

Description

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.