我在/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); }))
Run Code Online (Sandbox Code Playgroud)
怎么:-!!办?
C中未命名的位域有什么用?
示例:
typedef struct fun {
unsigned int :8;
unsigned int foo1 :1;
unsigned int foo2 :1;
unsigned int foo3 :1;
unsigned int foo4 :1;
unsigned int foo5 :1;
}dig;
Run Code Online (Sandbox Code Playgroud)
有什么用途:
unsigned int :8;
Run Code Online (Sandbox Code Playgroud)