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


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


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