Linux Kernel
3.7.1
|
#include <asm/bug.h>
Go to the source code of this file.
Macros | |
#define | BUILD_BUG_ON_NOT_POWER_OF_2(n) BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0)) |
#define | BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) |
#define | BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); })) |
#define | BUILD_BUG_ON_INVALID(e) ((void)(sizeof((__force long)(e)))) |
#define | BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) |
#define | BUILD_BUG() |
Enumerations | |
enum | bug_trap_type { BUG_TRAP_TYPE_NONE = 0, BUG_TRAP_TYPE_WARN = 1, BUG_TRAP_TYPE_BUG = 2 } |
#define BUILD_BUG | ( | ) |
BUILD_BUG - break compile if used.
If you have some code that you expect the compiler to eliminate at build time, you should use BUILD_BUG to detect if it is unexpectedly used.
BUILD_BUG_ON - break compile if a condition is true. : the condition which the compiler should know is false.
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.
#define BUILD_BUG_ON_NOT_POWER_OF_2 | ( | n | ) | BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0)) |
enum bug_trap_type |