Topic: short bitfields


Author: jamshid@emx.cc.utexas.edu (Jamshid Afshar)
Date: 4 Jun 1993 18:01:49 -0500
Raw View
In article <1993May28.182114.9383@microsoft.com> jimad@microsoft.com (Jim Adcock) writes:
>In article <C7MyyL.2F5@cbnewse.cb.att.com> grumpy@cbnewse.cb.att.com (Paul J Lucas) writes:
>| It seems plain as day on p. 185:
>|  ...C++ allows a bit-field to be of any integral
>|  type...including their signed and unsigned varieties.
>Nits:
>1) The passage you quote is part of an ARM commentary, and thus is not
>a binding part of the ANSI/ISO base documents.

True, but 9.6 proper does say "A bit-field must have integral type"
where 3.6.1 defines integral types as all sizes and enumerations (hmm,
"enum { false, true } b1 : 1;" -- ugh).

>2) ARM doesn't require that shorts be strictly longer than chars,

True.

>nor >= 16 bits, so that 10 bits might not fit in a short.

ANSI C, the other base document, does require that USHRT_MAX be at
least 65535 (see ARM 3.2c).  Doesn't this lead to the requirement that
short must be >= 16 bits, or are there some hypothetical holes?

Jamshid Afshar
jamshid@emx.utexas.edu




Author: dcb@slsvitt (David Binderman 3841)
Date: Tue, 25 May 93 18:47:41 GMT
Raw View
Hello there,

Is the following legal code ?

struct S {
 unsigned short t : 10;
};

Its not clear to me from reading the ANSI C++ WP Jan 28 1993, sections
9.6 and 3.6.1, or the ARM.

Six out of eight different C++ compilers seem happy about it.

Regards


David C Binderman     Dept US/ESI, Bau 60, SEL-Alcatel AG, Lorenz Strasse 10,
D-7000 Stuttgart 40, Germany      dcb@us-es.sel.de   Tel: +49 711 821 3841
The biggest difference between us and all the other bands is that we are
different - Half Man Half Biscuit




Author: grumpy@cbnewse.cb.att.com (Paul J Lucas)
Date: Wed, 26 May 1993 13:32:43 GMT
Raw View


Author: steve@taumet.com (Steve Clamage)
Date: Wed, 26 May 1993 18:12:59 GMT
Raw View
dcb@slsvitt (David Binderman 3841) writes:


>Is the following legal code ?

>struct S {
> unsigned short t : 10;
>};

>Its not clear to me from reading the ANSI C++ WP Jan 28 1993, sections
>9.6 and 3.6.1, or the ARM.

>Six out of eight different C++ compilers seem happy about it.

In Standard C, a bitfield must be declared "int", "signed int", or
"unsigned int".  Some C compilers allow other integral types as an
extension.

C++ allows any integral type (and now also any enum type) for a
bitfield, so the above code is legal C++.

If you use a C++-to-C translator, the underlying C compiler might
complain if the "unsigned short" is passed through rather than being
converted to "unsigned int".
--

Steve Clamage, TauMetric Corp, steve@taumet.com




Author: jimad@microsoft.com (Jim Adcock)
Date: 28 May 93 18:21:14 GMT
Raw View
In article <C7MyyL.2F5@cbnewse.cb.att.com> grumpy@cbnewse.cb.att.com (Paul J Lucas) writes:
|From article <1993May25.184741.28639@us-es.sel.de>, by dcb@slsvitt (David Binderman 3841):
|> struct S {
|>  unsigned short t : 10;
|> };
|
| It seems plain as day on p. 185:
|
|  ...C++ allows a bit-field to be of any integral
|  type...including their signed and unsigned varieties.

Nits:

1) The passage you quote is part of an ARM commentary, and thus is not
a binding part of the ANSI/ISO base documents.

2) ARM doesn't require that shorts be strictly longer than chars,
nor >= 16 bits, so that 10 bits might not fit in a short.

Needless to say I agree that both these issues *ought* to be clearly
addressed in the WPs.  Have they been, or will they be ?