Skip to main content

Timeline for When should you use bools in C++?

Current License: CC BY-SA 3.0

11 events
when toggle format what by license comment
S Apr 24, 2012 at 10:58 history suggested Dynamic CC BY-SA 3.0
general fixes
Apr 24, 2012 at 10:46 review Suggested edits
S Apr 24, 2012 at 10:58
Apr 20, 2012 at 20:18 comment added Craige Also found elsewhere on the web: "The obvious next question is 'how much memory do variables of different data types take?'. The size of a given data type is dependent on the compiler and/or the computer architecture. On most 32-bit machines (as of this writing), a char is 1 byte, a bool is 1 byte, a short is 2 bytes, an int is 4 bytes, a long is 4 bytes, a float is 4 bytes, and a double is 8 bytes."
Apr 20, 2012 at 20:17 comment added Craige @Apoc - 1 byte, actually. See also: stackoverflow.com/questions/266870/…
Apr 20, 2012 at 19:21 comment added DogDog I thought booleans in C++ were the same size as ints, 4 bytes.
Apr 20, 2012 at 16:23 comment added Craige +1. It makes the intent/options clear. You could use any method you like to store the value including a string with the value "yes" or "no", but you should choose the one that makes MOST sense. In this case, that is a boolean.
Apr 20, 2012 at 15:42 comment added Michael Shopsin Bools prevent abuse of a variable for other uses. An integer can be set to values other than 0 or 1 to create additional states your code may not be aware of.
Apr 20, 2012 at 11:22 vote accept Bugster
Apr 20, 2012 at 11:06 comment added Scott C Wilson To restate @AndrewFinnel's point: Bool is more self documenting. A variable you set to 0 or 1 could be a counter; a variable you set to true or false is clearly a flag.
Apr 20, 2012 at 11:02 comment added ChrisF Agreed. I think design intentions are more important. Only occasionally will you need to override them.
Apr 20, 2012 at 10:39 history answered Andrew T Finnell CC BY-SA 3.0