Help with bit-field semantics in C and C++
Mike Stump
mrs@apple.com
Tue Aug 24 22:31:00 GMT 2004
On Tuesday, August 24, 2004, at 03:02 PM, David Carlton wrote:
> I'm certainly not intending to be clever here. I would say, actually,
> that I'm trying to be as naive as possible in my reading.
That is in general dangerous.
> I dunno. I ran this example:
>
> enum Small { Zero = 0, One = 1, Two = 2, Three = 3 };
>
> Small x = (Small) 7;
>
> switch ( x ) {
> case Zero:
> return zero();
> case One:
> return one();
> case Two:
> return two();
> case Three:
> return three();
> }
>
> by a couple of people who walked by my cubicle, before showing them
> the standard. Their first reaction is that they would expect the
> switch statement to fall through.
That doesn't surprise me.
> When I showed them the standard, they agreed that it wouldn't fall
> through.
Then they misread the standard. The conversion is unspecified, there
is nothing that prohibits it from having the value 7 and from the
switch statement from falling through.
> * Users would be disappointed if the above example were to, say, core
> dump (which is behavior that is being proposed in some messages on
> this thread).
Agreed.
More information about the Gcc
mailing list