446,190 Members | 833 Online
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,190 IT Pros & Developers. It's quick & easy.

# bool

 P: n/a I have written a small main function . I have defined one bool variable and cout this variable , I found the value of this bool variable is 64. Since, I am using 32-bit addressing . My program is int main() { bool ab; cout<
7 Replies

 P: n/a yashwant pinge wrote: I have written a small main function . I have defined one bool variable and cout this variable , I found the value of this bool variable is 64. That would be very strange. Since, I am using 32-bit addressing . What does the value of a bool have to do with the size of an address? My program is int main() { bool ab; cout<

 P: n/a On 14 Mar, 12:17, "yashwant pinge"

 P: n/a "yashwant pinge" I have written a small main function . I have defined one bool variable and cout this variable , I found the value of this bool variable is 64. Since, I am using 32-bit addressing . My program is int main() { bool ab; cout<

 P: n/a On Mar 14, 5:08 pm, "Jim Langston"

 P: n/a On 2007-03-14 14:05, yashwant pinge wrote: On Mar 14, 5:08 pm, "Jim Langston" "yashwant pinge" I have written a small main function . I have defined one bool variable and cout this variable , I found the value of this bool variable is 64. Since, I am using 32-bit addressing . My program is int main() { bool ab; cout<

 P: n/a On 14 Mar, 13:53, Erik Wikström

 P: n/a Erik Wikström wrote: > Because 1 is the smalles possible value. Theoretically a bool does not need to take more space than on bit, but due to alignment requirements and such that would leave at least 7 bits in that byte unused, so the effective space used would still be at least one byte. Note though that the 1 of sizeof(bool) does not mean 1 byte, but rather a piece of memory as large as a char (which is the smallest addressable unit in C++), which just happens to be one byte on most machines. The above is wrong on several accounts. First, byte in C++ is defined in terms of char. A char variable by definition in the language is one byte. This unfortunately is a major defect in C++ portability. char plays double duty: 1. It's the native character type. 2. It's the smallest addressable storage unit. When all the world is eight bit ascii this is not an issue. It's problematic when the native character is LARGER than the minimal addressable storage (for example a machine with addressable units of 8 bits, but the native char wants to be 16). wchar_t is a poor substitute as there are a number of important interfaces that do not have wchar_t analogs. You have to kludge it by inventing a multibyte (conversion of the wchar_t type to a sequence of chars) even when such a thing doesn't uniquely exist. Further, no C++ type can be less than the byte size (sizeof char). This is also fundamanetal. It has nothing to do with alignment. It has to do with the fact that C++'s pointer behavior assumes that things aren't smaller than char. Mar 15 '07 #8

### This discussion thread is closed

Replies have been disabled for this discussion.