This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: How to use _Generic with bit-fields
- From: Joseph Myers <joseph at codesourcery dot com>
- To: Wink Saville <wink at saville dot com>
- Cc: Martin Sebor <msebor at gmail dot com>, GCC Development <gcc at gcc dot gnu dot org>
- Date: Tue, 23 Feb 2016 00:14:51 +0000
- Subject: Re: How to use _Generic with bit-fields
- Authentication-results: sourceware.org; auth=none
- References: <CAKk8iso7KLotY1WGwaO8FBvp27nFORAWdShqVGth=0Hrc+WVbQ at mail dot gmail dot com> <56C78A87 dot 4090601 at gmail dot com> <CAKk8isoF4gT_z9sscYmnetMZOCkaZUO0Gr9_sj7WQB86PEQxZg at mail dot gmail dot com> <alpine dot DEB dot 2 dot 10 dot 1602222140420 dot 26576 at digraph dot polyomino dot org dot uk> <CAKk8isr=pPy2v3vNhV5pMEz5bHpg9xUx_ExKEESU5i+xcbEjzg at mail dot gmail dot com> <alpine dot DEB dot 2 dot 10 dot 1602222345290 dot 26576 at digraph dot polyomino dot org dot uk> <CAKk8isqN7CXrPBBKjOH7OcRA2e+chO5QpzxRnGqL+VS-SULd9A at mail dot gmail dot com>
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