The code was imported from /usr/include/linux/kernel.h
/* Force a compilation error if condition is true, but also produce a
result (of value 0 and type size_t), so the expression can be used
e.g. in a structure initializer (or where-ever else comma expressions
aren't permitted). */
#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
#define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); }))
Here :-!!I don't know what
is.
Why did I use !!
instead of !
to check true/false?
This is a code that checks if e
can be given a value of 0
, and if it cannot be 0, it will fail during the build process.
Personally, the macro name is ...If you say
, it would be a more accurate expression.BUILD_BUG_OR_ZERO
rather than ON_ZERO
This code sizeof(structure { int: -!!(e);})
is read
It would have been better to use assert()
, but the reason why I did this without assert()
is because
assert()
can catch errors in runtime tests
This macro can catch errors in compilation tests earlier than that.
© 2024 OneMinuteCode. All rights reserved.