Why use !!(condition) instead of (condition)? [duplicate]

Well if the variable you are applying !! is not already a bool(either zero or one) then it will normalize the value to either 0 or 1.

With respect to __builtin_expect this kernel newbies thread discusses the notation and one of the responses explains (emphasis mine):

The signature of __builtin_expect

http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html) is:

long __builtin_expect (long exp, long c)

Note that the exp parameter should be an integral expression, thus no pointers
or floating point types there. The double negation handles the conversion from
these types to integral expressions automatically
. This way, you can simply
write: likely(ptr) instead of likely(ptr != NULL)
.

For reference in C99 bool macro expands to _Bool, true expands to 1 and false expands to 0. The details are given in the draft standard section 7.16 Boolean type and values .

Logical negation is covered in 6.5.3.3 Unary arithmetic operators in paragraph 5:

The result of the logical negation operator ! is 0 if the value of its operand compares
unequal to 0, 1 if the value of its operand compares equal to 0. The result has type int.
The expression !E is equivalent to (0==E).

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)