Possible Duplicate:
Double Negation in C++ code
When I scanned the Webkit source code, I found a strange use of the boolean "not" operator !
:
BOOL enabled;
if (SUCCEEDED(sharedPreferences->continuousSpellCheckingEnabled(&enabled)))
continuousSpellCheckingEnabled = !!enabled;
if (SUCCEEDED(sharedPreferences->grammarCheckingEnabled(&enabled)))
grammarCheckingEnabled = !!enabled;
Why don't they use enabled
directly instead of !!enabled
?
That treats 2 as a boolean value (which is considered true). To ask if x is 1 or 2, say x ==1 || x == 2. In English, is sometimes means "is equal to", and sometimes means "has the property".
A Boolean variable has only two possible values: true or false. It is common to use Booleans with control statements to determine the flow of a program.
Show activity on this post. According to the R language definition, the difference between & and && (correspondingly | and || ) is that the former is vectorized while the latter is not.
It's a C++ trick to convert anything to 1
or 0
.
For example, 42
is logically true
, but is not 1
, so applying !!
to it, you turn it into 1
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With