This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: bool


Jason Merrill <jason@cygnus.com> writes:
> Nonsense.  Most uses of bool are to store boolean values.  Most of these
> values would have been type 'int' if 'bool' were not available.  If you
> want packed data, you can use a bitvector or 'unsigned char'.

Most uses of short are to store integer values.  Most of these
values would have been type 'int' if 'short' were not available.
What's your point?

My point is about user expectations and standardization.
Most users will be surprised if bool takes 4 bytes.
The natural expectation is that bool is one byte.

I people want to pack more than one bool per byte, they can use bitvector.
If they want the fastest type, they can use int.  But the default should
be one byte, at least in structures and arrays (which implies that
sizeof(bool)==1.

I have no problem with the compiler behind the scenes using 4 bytes for
a stand-alone bool auto or static variable.  But not in structs or arrays.

Another (minor) argument concerns Java compatibility:  The Java
Native Interface defines jbool (the C/C++ typedef that matches
thye Java boolean type) as a one-byte unsigned.  This is not
a major issue, since we can always:
	typedef unsigned char jbool;
but it would be nicer to:
	typedef bool jbool;

	--Per Bothner
Cygnus Solutions     bothner@cygnus.com     http://www.cygnus.com/~bothner


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]