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]
Other format: [Raw text]

Re: Help with bit-field semantics in C and C++


Mike Stump <mrs@apple.com> writes:

| 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...

Huh?  Exactly which part of the above quote do you derive that from?

| Therefore, the underlying type of enum { foo } can be char. a signed

It can be char as as it could be bool, if bool is no larger than int
-- and GCC makes bool no larger than int.

| 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

If you change the (input) problem, you should expect a different
output.  The enum

     enum { foo = 3 } e;

out to be represented by an integer type large enough to represent the
value 3.  Can bool do that? No.  so, the new example you bring does
not bear much relevance to the original example at discussion.
The Standard syas that basically, we need to store in that enum, any
value we can store in

   strutc X {
      <integer-type> enum_value : 2;
   };

===
   For an enumeration where emin is the smallest enumerator and emax
   is the largest, the values of the enumeration are the values of the
   underlying type in the range bmin to bmax, where bmin and bmax are,
   respectively, the smallest and largest values of the smallest
   bit-field that can store emin and emax.81) It is possible to define
   an enumeration that has values not defined by any of its
   enumerators. 
===

therefore if, <integer-type> above is unsigned char, we can store the
values 0, 1, 2, 3 in that enum. 

| e = 7;
| if (e == 7) ...
| 
| mandated to equal 7, or we don't.  I contend the standard mandates it
| be 7.

Chapter and verse please?

|  I contend that the way you are presenting this is at best
| misleding, and that it what I am objecting to.

I think you're objecting to strawmen you've made.

| Also, bools can take on values that are neither true nor false.

The issue is not whether bool can take other value that are neither
true or false.  By the way,
3.9.1/6
 
  Values of type bool are either true or false.42)


-- Gaby


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