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


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~


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