这是什么!(x)的平均值在C(尤指Linux内核)? [英] What does !!(x) mean in C (esp. the Linux kernel)?

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

问题描述

我已经通过Linux内核阅读(特别是,2.6.11)。
我碰到下面的定义来了:

 的#define不可能的(X)__builtin_expect(!!(X),0)

(从Linux-2.6.11 /在include / linux / compiler.h:61的 LXR链接

这是什么!完成?为什么不直接使用(X)?


  

参见:


  
  

解决方案

!!(X)力量它是0或1 0 0保留,但任何非零值(这将是一个布尔上下文中真)成为1。

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)

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

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

See also:

解决方案

!!(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天全站免登陆