gpt4 book ai didi

c - 符号的使用 | & &~ 和 ~ 在 capability.h 文件中

转载 作者:太空狗 更新时间:2023-10-29 15:49:02 26 4
gpt4 key购买 nike

我正在读取给定 here 的文件 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;
}

在以下系统调用中使用&:

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;
}

&~在以下函数中的使用:

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;
}

~ 在以下函数中的使用:

static inline kernel_cap_t cap_invert(const kernel_cap_t c)
{
kernel_cap_t dest;
CAP_UOP_ALL(dest, c, ~);
return dest;
}

最佳答案

例如 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)

所以“表达”

CAP_BOP_ALL(dest, a, b, |);

扩展为

do {
unsigned __capi;
for (__capi = 0; __capi < _KERNEL_CAPABILITY_U32S; ++__capi) {
dest.cap[__capi] = a.cap[__capi] | b.cap[__capi];
}
} while (0);

.尽管原始表达式看起来不像正确的 C,但这是因为 C 解析器仅在预处理器完成后才获取它并使其看起来像后一个表达式。

关于c - 符号的使用 | & &~ 和 ~ 在 capability.h 文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14264571/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com