This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Help with bit-field semantics in C and C++
- From: Mike Stump <mrs at apple dot com>
- To: Gabriel Dos Reis <gdr at integrable-solutions dot net>
- Cc: Joe Buck <Joe dot Buck at synopsys dot COM>, Roger Sayle <roger at eyesopen dot com>, Mark Mitchell <mark at codesourcery dot com>, gcc at gcc dot gnu dot org
- Date: Tue, 24 Aug 2004 14:18:17 -0700
- Subject: Re: Help with bit-field semantics in C and C++
On Tuesday, August 24, 2004, at 01:12 PM, Gabriel Dos Reis wrote:
The underlying type of E needs only be an integer type large enough to
contain a data expressible with a single bit
7 Types bool, char, wchar_t, and the signed and unsigned integer types
are collectively called integral types.43) A synonym for integral type
is integer type. The representations of integral types shall define
values by use of a pure binary numeration system.44) [Example: this
International Standard permits 2's complement, 1's complement and
signed magnitude representations for integral types. ]
5 The underlying type of an enumeration is an integral type that can
represent all the enumerator values defined in the enumeration. It is
implementation-defined which integral type is used as the underlying
type for an enumeration except that the underlying type shall not be
larger than int unless the value of an enumerator cannot fit in an int
or unsigned int. If the enumerator-list is empty, the underlying type
is as if the enumeration had a single enumerator with value 0. The
value of sizeof() applied to an enumeration type, an object of enumer-
ation type, or an enumerator, is the value of sizeof() applied to the
underlying type.
The intent of the standard is not to confuse bool into this...
Therefore, the underlying type of enum { foo } can be char. a signed
integer type or an unsigned integer type. We can see this by using
using enum { foo = 3 } e in the analysis. Either, we come up with
e = 7;
if (e == 7) ...
mandated to equal 7, or we don't. I contend the standard mandates it
be 7. I contend that the way you are presenting this is at best
misleding, and that it what I am objecting to.
Also, bools can take on values that are neither true nor false.