!!(x) 在 C(尤其是 Linux 内核)中是什么意思? [英] What does !!(x) mean in C (esp. the Linux kernel)?

查看:32
本文介绍了!!(x) 在 C(尤其是 Linux 内核)中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读 Linux 内核(特别是 2.6.11).我遇到了以下定义:

I've been reading through the Linux kernel (specifically, 2.6.11). I came across the following definition:

#define unlikely(x)     __builtin_expect(!!(x), 0)

(来自 linux-2.6.11/include/linux/compiler.h:61 lxr 链接)

(from linux-2.6.11/include/linux/compiler.h:61 lxr link)

有什么用!!完成?为什么不直接使用 (x)?

What does !! accomplish? Why not just use (x)?

推荐答案

!!(x) 强制它为 0 或 1.0 仍为 0,但任何非零值(即在布尔上下文中为真")变为 1.

!!(x) forces it to be either 0 or 1. 0 remains 0, but any non-zero value (which would be 'true' in a boolean context) becomes 1.

这篇关于!!(x) 在 C(尤其是 Linux 内核)中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆