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: How does logical negation work in C? Double Negation in C++ code.
!!(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)
1.4m articles
1.4m replys
5 comments
57.0k users