What does !!(x) mean in C (esp. the Linux kernel)?

后端 未结 3 903
被撕碎了的回忆
被撕碎了的回忆 2020-11-30 07:49

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)         


        
3条回答
  •  南笙
    南笙 (楼主)
    2020-11-30 08:19

    !!(x) is equivalent to (x) != 0 (unless some very oddball operator overloading is going on in C++).

    The fact that it's not obvious what !!(x) is doing is a probably a good reason to use (x) != 0. Unless you want to be an elite kernel hacker.

    See this closed question (if it's still around) for a discussion of the merits of !! (maybe that question will be be reopened, since this question indicates that it has some value).

提交回复
热议问题