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

Gabriel Dos Reis gdr@integrable-solutions.net
Tue Aug 24 23:45:00 GMT 2004


Joe Buck <Joe.Buck@synopsys.COM> writes:

| [ here E is a four-valued enum, 0,1,2,3 ]
| 
| On Tue, Aug 24, 2004 at 04:09:02PM -0700, Mike Stump wrote:
| > (E)n, where n is an int with value, say of 7, is permitted by the 
| > standard to take on the value 7.  This is because the text of the 
| > standard says the value is unspecified.  7 is a unspecified value, 
| > honest.
| 
| I agree with you so far; (E)n might be 7.

I disagree that the enum object would have value 7, as 7 is not an
enumeration (E) value.

| The next question, then, is whether, despite this, a compiler is allowed
| to implement a switch on a variable of type E as a jump table, in such a
| way that a value outside of [0,3] malfunctions (jumps to a random address).

By the type properties confered to E, any value of that type is in the
range [0,3]. 

| Let's leave to one side whether this is a good idea.  Is it permitted?

That can't happen.

-- Gaby



More information about the Gcc mailing list