[comp.unix.wizards] bitfields

wmam@sphinx.UChicago.UUCP (tony mason) (11/26/86)

[***]

Ok, folks, here is the burining question of the hour:  how are bit fields in
C dealt with?  As I read K&R arrays of bit fields are allowed, HOWEVER, in
the Microsoft C compiler Version 4.0, they explicitly state that they are not
allowed.  Which is it?  Has X3J11 come up with anything regarding this?  I
can sympathize with Microsoft and other 'C' compiler manufacturers about
implementing this, but, if they don't, they really should tell you that this
is a deviation.

Any and all input is appreciated in this regard.  I would especially like to
hear from anyone on X3J11, other 'C' compiler makers and (quite unlikely from
what I hear) Microsoft.

I look forward to hearing!


Tony Mason             >>>>>>>>> University of Chicago <<<<<<<<<<<
uucp:  ...ihnp4!gargoyle!sphinx!wmam, ...ihnp4!gargoyle!euler!tony
bitnet:   wmam%sphinx@UChicago.Bitnet
ARPA:     m1.spokane%UChicago.Mailnet@MIT-Multics.ARPA

jpn@teddy.UUCP (John P. Nelson) (12/01/86)

>Ok, folks, here is the burining question of the hour:  how are bit fields in
>C dealt with?  As I read K&R arrays of bit fields are allowed, HOWEVER, in
>the Microsoft C compiler Version 4.0, they explicitly state that they are not
>allowed.

If K&R is Kernighan and Ritchie, I suggest you reread it.  Arrays of bitfields
are EXPLICITLY disallowed  (See the last paragraph in section 6.7) - but in
any case, an array of bitfields is impossible, not just difficult - Remember
that a reference to an array (not just an element of it) evaluates to an
ADDRESS - However, taking the address of a bit field is also explicitly
disallowed.  Here is part of the relavent paragraph from K&R

     Other restritrictions (of bit fields) to bear in mind:  ...   They are
     not arrays; they do not have addresses, so the & operator cannot be
     applied to them.

and again, in appendix A where structures are formally defined (section 8.5):

     ... In all implementations, there are no arrays of fields, and the
     address-of operator '&' may not be applied to them, so that there are no
     pointers to fields.

throopw@dg_rtp.UUCP (Wayne Throop) (12/01/86)

(Note that this discussion in more properly a language discussion, not
 an OS discussion.  I've therefore cross-posted, and set the followup to
 comp.lang.c.)

> wmam@sphinx.UChicago.UUCP (tony mason)
> [...] how are bit fields in C dealt with?  As I read K&R arrays of bit
> fields are allowed [...].  Has X3J11 come up with anything regarding
> this? [...]

Since K&R define array subscripting in terms of pointer arithmetic, and
since taking the address of a bitfield is not allowed by K&R, how can
you possibly conclude that bitfield arrays are allowed?  Breifly,
paraphrasing a lof of what I find in X3J11, bitfield definitions are
legal only on struct members of integral type.  Harbison and Steele warn
that some compilers only allow bitfield modifiers on *unsigned* integral
typed struct members.  K&R say similar things.  So again... what passage
in K&R led you to think that arrays of bitfields were sensible in C?

--
Sometimes I think the only universal in the computing field is the
fetch-execute cycle.
                                --- Alan J. Perlis
-- 
Wayne Throop      <the-known-world>!mcnc!rti-sel!dg_rtp!throopw

tim@ism780c.UUCP (Tim Smith) (12/03/86)

In article <844@sphinx.UChicago.UUCP> wmam@sphinx.UUCP (tony mason) writes:
>
> As I read K&R arrays of bit fields are allowed, HOWEVER, in the 
> Microsoft C compiler Version 4.0, they explicitly state that they
> are not allowed.

K&R page 197, first paragraph, last sentence:

	In all implementations, there are no arrays of fields, and
	the address-of operator & may not be applied to them, so
	that there are no pointers to fields.

-- 
emordnilapregnolanalpanama

Tim Smith       USENET: sdcrdcf!ism780c!tim   Compuserve: 72257,3706
                Delphi or GEnie: mnementh