This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Help with bit-field semantics in C and C++
- From: Richard Henderson <rth at redhat dot com>
- To: Mark Mitchell <mark at codesourcery dot com>
- Cc: Mike Stump <mrs at apple dot com>, Gabriel Dos Reis <gdr at integrable-solutions dot net>, Dave Korn <dk at artimi dot com>, "'Roger Sayle'" <roger at eyesopen dot com>, "'Joe Buck'" <Joe dot Buck at synopsys dot com>, gcc at gcc dot gnu dot org
- Date: Tue, 24 Aug 2004 16:45:24 -0700
- Subject: Re: Help with bit-field semantics in C and C++
- References: <195B2A50-F60D-11D8-AF5A-003065BDF310@apple.com> <412BAEF5.6010302@codesourcery.com>
I'm going to sidestep the question of whether or not the compiler
should force the value into a valid range upon cast or assignment
and ask a different question.
Is TYPE_PRECISION (t) < GET_MODE_PRECISION (TYPE_MODE (t)) the
correct representation?
I submit that it is not. Primarily becuase of the masking
semantics that we require for this case due to C bitfields.
I wonder if a better representation would be subrange types,
as seen in Ada. This case has characteristics:
TREE_CODE (enum_type) == INTEGER_TYPE
TREE_TYPE (enum_type) == compatible_int_type
TYPE_MODE (enum_type) == TYPE_MODE (compatible_int_type)
TYPE_PRECISION (enum_type) == TYPE_PRECISION (compatible_int_type)
TYPE_MIN_VALUE (enum_type) == subrange start value
TYPE_MAX_VALUE (enum_type) == subrange end value
The precision and mode are set such that we see that mask
operations are not required, but min and max are set to a
reduced range so that we can see that we're dealing with a
constrained set of values.
r~