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

Mike Stump mrs@apple.com
Wed Aug 25 01:16:00 GMT 2004


On Tuesday, August 24, 2004, at 04:20  PM, Gabriel Dos Reis wrote:
> for which the minimum bits of representation is 1, 7 is not an
> enumeration value.  A fortiori, it is not a honest unspecified
> enumeration value.

The honest qualifier doesn't appear in my definition of the C++ 
language; it only has specified and unspecified values.

Another way to think about this is to examine:

#include <stdio.h>
#include <string.h>

enum E { foo = 3 } e;

int
main() {
   memset (&e, ~(unsigned char)0, sizeof (e));
   printf ("%u\n", (unsigned int)e);
}

The above program violates no rules of C++.  The value printed is 
either specified, or unspecified.  Which do you think it is, and if 
specified, which value is printed?

The main point is, either it is 3 or some other value.  To get the 
value 3, we must always mask or perform a bit-field operation, which is 
costly, in general, we want to avoid costly operations.

If you survey all C++ compilers in the world that have ever been, I 
think you'll discover they produce the same category of answer, 
further, I suspect this answer matches C quite closely.



More information about the Gcc mailing list