Reg*_*ser 3 c posix linux-kernel embedded-linux
我正在阅读这里给出的文件capability.h
我不清楚如何在函数调用中使用符号| ~ &以及&~它们在做什么
使用|以下函数调用:
static inline kernel_cap_t cap_combine(const kernel_cap_t a,
const kernel_cap_t b)
{
kernel_cap_t dest;
CAP_BOP_ALL(dest, a, b, |);
return dest;
}
Run Code Online (Sandbox Code Playgroud)
使用&以下系统调用:
static inline kernel_cap_t cap_intersect(const kernel_cap_t a,
const kernel_cap_t b)
{
kernel_cap_t dest;
CAP_BOP_ALL(dest, a, b, &);
return dest;
}
Run Code Online (Sandbox Code Playgroud)
使用&~以下功能:
static inline kernel_cap_t cap_drop(const kernel_cap_t a,
const kernel_cap_t drop)
{
kernel_cap_t dest;
CAP_BOP_ALL(dest, a, drop, &~);
return dest;
}
Run Code Online (Sandbox Code Playgroud)
使用~以下功能:
static inline kernel_cap_t cap_invert(const kernel_cap_t c)
{
kernel_cap_t dest;
CAP_UOP_ALL(dest, c, ~);
return dest;
}
Run Code Online (Sandbox Code Playgroud)
例如,CAP_BOP_ALL定义为
#define CAP_BOP_ALL(c, a, b, OP) \
do { \
unsigned __capi; \
CAP_FOR_EACH_U32(__capi) { \
c.cap[__capi] = a.cap[__capi] OP b.cap[__capi]; \
} \
} while (0)
Run Code Online (Sandbox Code Playgroud)
所以"表达"
CAP_BOP_ALL(dest, a, b, |);
Run Code Online (Sandbox Code Playgroud)
扩展到
do {
unsigned __capi;
for (__capi = 0; __capi < _KERNEL_CAPABILITY_U32S; ++__capi) {
dest.cap[__capi] = a.cap[__capi] | b.cap[__capi];
}
} while (0);
Run Code Online (Sandbox Code Playgroud)
.尽管原始表达式看起来不像正确的C,但这是因为C语法分析器仅在预处理器完成时获取它并使其看起来像后一个表达式.