How to use _Generic with bit-fields
Joseph Myers
joseph@codesourcery.com
Tue Feb 23 00:14:00 GMT 2016
On Mon, 22 Feb 2016, Wink Saville wrote:
> I understand "long" bit fields are in ISO, but its a gcc extension so
> it would seem it should play nice with as much of the language as
> possible.
>
> It seems the root of the problem here is the length encoding
> in the type, why does gcc do that, does the standard
> require it?
See the previously identified analysis of the textual history, the various
C90 and C99 DRs involved, and how (as noted in 1993 in DR#120, and as is
still the case) there is *no definition whatever* in ISO C of what value
would be stored in a bit-field by an assignment of a value out of range of
an integer type with the given number of bits, other than through the
rules for conversions, which only apply if you consider the bit-field to
have the restricted-width type. (And, if you wish, you could do the
archaeology around the many bugs that were fixed in GCC by giving
bit-fields types reflecting the values they could actually represent.)
The root of the "problem" is using the extension of bit-fields wider than
int, a feature that simply doesn't fit well into the C language and has
unintuitive consequences.
--
Joseph S. Myers
joseph@codesourcery.com
More information about the Gcc
mailing list