Re:Linus: bool is dangerous in C if you don't understand it
by chrismcb on Sunday September 01, 2013 @02:22AM
(#6309333)
Why not make the correct comparison and do BOOL b = pointer != NULL. Now the code says what you mean, is easy to understand, and assigns a boolean value to a bool.
Re:Linus: bool is dangerous in C if you don't understand it
by to3m on Sunday September 01, 2013 @10:44AM
(#6310553)
!!p does the same as p!=NULL. The choice is purely stylistic. (!p is equivalent to p==NULL; !!p is therefore equivalent to !(p==NULL). Or, alternatively, p!=NULL.)
Re:Linus: bool is dangerous in C if you don't understand it
by tel on Sunday September 01, 2013 @12:04PM
(#6310879)
Because the properties of other types might not translate. It's probably okay with integer types since (a + b) => (a OR b) and (a * b) => (a AND b) as long as you stay away from upper bounds.
But some semantic maps are less great. Having your compiler help you to ensure you're not implicitly mixing up bad maps can be helpful.
If you treat it this way you remove the vast majority of the problems with most C or C++ BOOL implementations.
The low bytes of a pointer being 0 (It can happen on Windows with VirtualAlloc and company) can screw up the works, so avoid assigning a pointer to a BOOL and use BOOL b = !!pointer if you have to break that rule.