What double negation does in C

Viewed 5700

I had a controversy about what compilers "think" about this:

a = 8;
b = !!a;

So, is b == 0x01 ? Is TRUE always 0x01 or it may be 0xFF, 0xFFFF, 0xFFFFFFFF etc..?

If I want to extract only 0x00 if (a == 0) and 0x01 if (a > 0) does this double negation approach works?

In other words: to obtain result only 0 or 1, what is better to use?

a) a>0?1:0; b) !!a

I hope you understand my question.

5 Answers
Related