Topic: the wisdom of a 1-byte bool type


Author: herbs@cntc.com (Herb Sutter)
Date: 1997/03/21
Raw View
[cross-posting this followup to csc++]

rmashlan@r2m.com (Robert Mashlan) wrote:
>I've just noticed that in Borland C++'s 32-bit compiler, and in
>something that I've read about Visual C++ 5.0, that both use a one
>byte bool, that is, sizeof(bool) == 1.
>
>At first glance, this might make sense, because it would save data
>space.  However, I think that bool would be better implemented as the
>natural integer size of the processor

Short answer: that's fine, and you can always use int.

Considering the trouble that's been taken to enforce a packed (bitwise)
specialization of vector<bool> in the standard, something I've questioned
primarily because it forces a possibly (and often) unwanted optimization
tradeoff on the programmer, this is somewhat amusing... :-)  While I
personally wouldn't care for bools of size int, either, at least this
request illustrates why we should be reluctant to choose optimization
tradeoffs for (and then force them on) programmers who may want to do
something else.  Maybe in the second standard...

BTW, the above is just critiquing the basic raison d'etre of
vector<bool>... for a summary of its actual technical problems, see the
earlier thread on this topic a month or two ago in csc++.

---
Herb Sutter (mailto:herbs@cntc.com)

Current Network Technologies Corp. (http://www.cntc.com)
2695 North Sheridan Way, Suite 150, Mississauga ON Canada   L5K 2N6
Tel 416-805-9088   Fax 905-822-3824
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]

      [ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]