Search code examples
cequationnot-operator

What is meaning of !! in C -- and why is it needed?


Possible Duplicate:
Double Negation in C++ code

While reading one code I read:

flush = ! !(flags & GST_SEEK_FLAG_FLUSH);

I am not getting what does !! mean here . what does this sentence do?

EDIT:

I got it its a double-negative. trick to convert non-bool data to bool

But what is the need of that? Here flush is bool then if you assign any non zero item to bool it will treat as 1 and zero item as 0 so whats benefit of doing this?


Solution

  • It's a double-negative. It's a way of converting an otherwise-non-bool expression (such as flags & GST_SEEK_FLAG_FLUSH) to a bool. I personally prefer:

    flush = (flags & GST_SEEK_FLAG_FLUSH) != 0;