Magmai,
My C++ book says that a bool is a two state type. It can only have true or false. When converting a bool to an int, true equates to 1, false to 0. When converting an int to a bool, zero equates to false, non-zero to true. A quick look at the disassembly shows that Borland converts ints to bools by doing a TEST, SETNZ, and an AND, rather than just a MOV, ensuring that bool only has 1 or 0 as its values.
Thanks,
Micah
Another Which is Faster
One reason to use if (!var) style rather than if (var == false):
Less errors because you avoid that double =''s, in which case you might only type in one.
Of course, thats only one reason, its your decision and style, but thats why i use ! style.
-----------------------------
A wise man once said "A person with half a clue is more dangerous than a person with or without one."
The Micro$haft BSOD T-Shirt
Less errors because you avoid that double =''s, in which case you might only type in one.
Of course, thats only one reason, its your decision and style, but thats why i use ! style.
-----------------------------
A wise man once said "A person with half a clue is more dangerous than a person with or without one."
The Micro$haft BSOD T-Shirt
-----------------------------A wise man once said "A person with half a clue is more dangerous than a person with or without one."The Micro$haft BSOD T-Shirt
ImmaGNUman,
I''ve heard that MSVC doesn''t have this feature, but Borland warns me when I use if(fred = 3) instead of if(fred == 3) by saying "Possibly incorrect assignment".
Otherwise I''d either use if(!x), or if(3 == fred), as no compiler should let you get away with if(3 = fred).
Thanks all
Micah.
I''ve heard that MSVC doesn''t have this feature, but Borland warns me when I use if(fred = 3) instead of if(fred == 3) by saying "Possibly incorrect assignment".
Otherwise I''d either use if(!x), or if(3 == fred), as no compiler should let you get away with if(3 = fred).
Thanks all
Micah.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement