sizeof bool > sizeof int ?!?

Gerald Pfeifer pfeifer@dbai.tuwien.ac.at
Sat Dec 18 17:14:00 GMT 1999


On Thu, 20 Aug 1998, Per Bothner wrote:
> The last time this came up, I lobbied for making sizeof(bool)
> be 1 byte.  I see little reason for making sizeof(bool) > sizeof(short)
> [...]
> Well, guess what?  I think most programmers *expect* sizeof(bool)
> to be 1 - but we are violating their very reasonable expectation.

I just checked and GCC 2.95.2 and Alpha still has sizeof bool == 8,
even with -fnew-api!

> Note we also have a framework for making incomaptible changes:
> -fnew-abi.  So I see no reason for not changing sizeof(bool) to 1
> in the new ABI.

Is there any chance this get's change, at least when we change the ABI?
I mean, at the very least this should be reduced to sizeof int!

And Mike Mike Stump <mrs@wrs.com> wrote:
> No.  Well, ok, I wasn't going to comment, but let me make one meta
> comment about this.  The most persuasive comment is one from a
> benchmark type person that measures the performance in a couple of
> different and realistic ways and makes a statement about the
> performance characteristics, the rest of us can sit back and debate if
> we want to blow the 5%, and save the space, and maybe be better to the
> cache.

Well, I *did* benchmarks back then with an AI system where I am one of the
developers, and there the difference was incredible:

We used lots of medium sized arrays of bool (with a couple of thousand
elements each) and an average alpha started swaping like crazy, until we
ran out of memory. Once we switched to arrays of char, our code became
significantly faster and consumed less than 100MB.


Again, there may be reasons not to bring down sizeof bool to 1 on that
platform, but sizeof bool > sizeof int is really, really weird! :-/

Gerald
-- 
Gerald "Jerry" pfeifer@dbai.tuwien.ac.at http://www.dbai.tuwien.ac.at/~pfeifer/



More information about the Gcc mailing list