Possible Duplicate:
Double Negation in C++ code
Let’s say:
bool var = !!true;
It will assign “true” to the variable. Seems useless, but I was looking at Visual Studio’s definition of “assert”, and it is:
#define assert(_Expression) (void)( (!!(_Expression)) || (_wassert(_CRT_WIDE(#_Expression), _CRT_WIDE(__FILE__), __LINE__), 0) )
Why does it negate the “_Expression” twice?
I wonder that they want to force the “!” operator to be called (in the case it is overloaded), but that doesn’t seem to be a good reason.
!!guarantees that the result will end up as a 1 or a 0, rather than just the value of_Expressionor 0. In C, it’s unlikely to matter, but in C++ I think it turns the result of the expression into abooltype, which might be useful in some cases. If you did have some API that required a literal 1 or 0 be passed to it, using!!would be a way to make it happen.