Why use two '!' operators on a boolean value?

boolean, c++

Solution

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`.

Problem

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`?

Original source

Related problems