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

Mark Mitchell mark@codesourcery.com
Tue Aug 24 19:32:00 GMT 2004


Dave Korn wrote:

> But 65535 is also a value that fits into the size of a short, but is
> <>outside the valid range; that's why I mentioned the old
> signedness-preserving vs. value-preserving dichotomy.

What I meant was that even if you convert 65535 to -1, -1 is still a 
short.  And, that conversion was free -- no instructions to generate.  
When you read from the memory used to store a short, you never get a 
value that is not-a-short.  The enum case is more like NaNs of Itanium's 
NaTs; it's "huh, what's this, this can't be one of these..."

> <> Actually, on second thoughts, the compiler could be made to only 
> apply the
> mask operation when it knows that a potentially-unsafe (because
> size-reducing) cast is being applied. Would that cover it?

Not really; C code compiled as C++ often converts between "int" and 
small enum types.

-- 
Mark Mitchell
CodeSourcery, LLC
(916) 791-8304
mark@codesourcery.com



More information about the Gcc mailing list