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

Richard Henderson rth@redhat.com
Tue Aug 24 23:48:00 GMT 2004


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~



More information about the Gcc mailing list