tags:

views:

281

answers:

6

Looking at some code I noticed that another dev had changed every instance of true to !false. Why would you do that? thx

+4  A: 

I have no idea and I've been writing C++ for a while. I suspect whatever he reasons were they weren't good ones.

Mike McQuaid
+1 for bad reasons. What is it about booleans that makes people distrust them?
Steve Gilham
Booleans can be false too!
kenny
@Steve: the fact that they didn't originally exist in C.
Mike McQuaid
A: 

I do not know actually but may be TRUE is not 1 (any thing > 0) and FALSE is zero so "not false" = 1 so he will be in safe place

Ahmed Said
Sorry - should've been clear - the datatypes are C++ bools, afaik these are either true=1 or false=0.
Cokes
I remember that there is data type in windows called BOOLEAN.Boolean variable (should be TRUE or FALSE).This type is declared in WinNT.h as follows:typedef BYTE BOOLEAN;
Ahmed Said
+7  A: 
MadKeithV
Agreed. He was probably once told to use !FALSE when using the TRUE/FALSE macros, but I see no reason to do so with a proper bool data type.
Roel
+3  A: 

I think this is a historical thing. IIRC there was a problem on some C/C++ compilers knowing what the compiler would use to represent as true. You can know false is zero hence !false will be whatever the current ABI will have as true.

Generically this is redundant but there are a few special case where it is useful but I can't think of one.

David Allan Finch
+1  A: 

maybe he got so many true and false in his code and he wanted to reverse it easily, he can just use his editor's search and replace,

newbie
+3  A: 

It might be necessary if the line

#define true false

just happened to be somewhere in the headers :)

IMil
+1 love that one.
kenny
Anyone who write that should be given a good beating!
KTC