This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: sizeof bool > sizeof int ?!?
- To: Richard Hadsell <hadsell at blueskystudios dot com>
- Subject: Re: sizeof bool > sizeof int ?!?
- From: Per Bothner <bothner at cygnus dot com>
- Date: Thu, 20 Aug 1998 16:31:23 -0700
- cc: EGCS mailing list <egcs at cygnus dot com>
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),
yet no-one argues for making sizeof(short) be 4 or 8 on any system,
even though it would be consistent with standards, and probably
more efficient. The thing is that people *expect* sizeof(short)
to be 2, and changing that would break some code, and make other
code be unacceptably bloated.
Well, guess what? I think most programmers *expect* sizeof(bool)
to be 1 - but we are violating their very reasonable expectation.
What we really want is for bool in arrays and structs to be 1 byte,
but bool as a standalone variable to be whatever is fastest,
or at least the compiler to act as if it were. Last time around
I was told that Gcc actualy does have the mechanism for something
like that - basically use full-words registers for bool local
variables. It was also suggested this would remove most of
the speed penalty of making bool be 1 byte.
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. (This assumes the back-end people can help
with whatever magic flags are needed to making this faster.)
--Per Bothner
Cygnus Solutions bothner@cygnus.com http://www.cygnus.com/~bothner