Article View: comp.std.c
Article #4135Re: bit fields
From: Dan Pop
Date: Thu, 28 Sep 1995 14:02
Date: Thu, 28 Sep 1995 14:02
42 lines
1900 bytes
1900 bytes
In <44c6g2$g42@news0.rain.rg.net> Paul Long <plong@perf.com> writes:
>danielv@crt0.crt (Daniel Villeneuve) wrote:
>>
>>From ANSI C 3.5.2.1:
>>
>>``A bit-field shall have a type that is a qualified or unqualified version
>>of one of _int_, _unsigned int_ or _signed int_.''
>>
>BTW, how's this for perverse? The 6.5.2.1 Semantics section says that "A
>bit-field is interpreted as an integral type consisting of the specified number
>of bits." So, as long as we "interpret" the type as integral, does this mean
>that the following is conforming?
>
> struct {
> float a : 3;
> };
Since when is "float" a ``qualified or unqualified version of one of
_int_, _unsigned int_ or _signed int_'' ?
>IOW, it looks like the Standard imposes NO requirements for the type of a
>bit-field.
It does. Read again the quote reproduced at the beginning of this
article.
>We just have to interpret the type as integral. Can anybody prove
>different? This would make a lot of C compilers non-conforming, such as acc and
>gcc.
No, it won't. Your example invokes undefined behaviour, because a
"shall" requirement which appears outside of a constraint is violated,
so no matter what the compiler does, including crashing and burning,
is the right thing.
Dan
--
Dan Pop
CERN, CN Division
Email: Dan.Pop@mail.cern.ch
Mail: CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
Technical Details
Message-ID:
<danpop.812296942@rscernix>Path:
arc1-ca.pugleaf.net!CERN.ch!rscernix!danpopReferences:
<446v7l$jn4@gozer.inri.com> <DANIELV.95Sep27083528@crt0.crt> <44c6g2$g42@news0.rain.rg.net>Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c Path: arc1-ca.pugleaf.net!CERN.ch!rscernix!danpop From: Dan.Pop@mail.cern.ch (Dan Pop) Subject: Re: bit fields X-Nntp-Posting-Host: ues5.cern.ch Message-ID: <danpop.812296942@rscernix> Sender: news@news.cern.ch (USENET News System) Organization: CERN European Lab for Particle Physics X-Newsreader: NN version 6.5.0 #7 (NOV) References: <446v7l$jn4@gozer.inri.com> <DANIELV.95Sep27083528@crt0.crt> <44c6g2$g42@news0.rain.rg.net> Date: Thu, 28 Sep 1995 14:02:22 GMT