Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!cbosgd!gatech!seismo!umcp-cs!chris From: chris@umcp-cs.UUCP (Chris Torek) Newsgroups: net.lang.c Subject: Re: problems with the C parser Message-ID: <1741@umcp-cs.UUCP> Date: Thu, 29-May-86 20:37:51 EDT Article-I.D.: umcp-cs.1741 Posted: Thu May 29 20:37:51 1986 Date-Received: Sat, 31-May-86 06:21:51 EDT References: <5072@topaz.RUTGERS.EDU> Organization: Computer Sci. Dept, U of Maryland, College Park, MD Lines: 44 Keywords: bitfield, structure Summary: There are no bitfield arrays. In article <5072@topaz.RUTGERS.EDU>, brisco@topaz.RUTGERS.EDU (T.p.), wanting to translate a Pascal packed array [0..31] of boolean writes: > ... I [tried]: > > typedef union { > int intfield; /* change the record name - keyword */ > struct bool{unsigned x[32]:1}; > } newtype; > > The C parser barfed all over this. I tried every combination >of unsigned x:1[32], ..... that I could think of. Out of frustration >I looked up the syntax of the declarations in K&R and found that the >initial guess had been correct! Hrum. Where in K&R did you find something that implies the above is in any way correct? Try instead chapter 6, page 138: Other restrictions to bear in mind: fields are unsigned; they may be stored only in int's (or, equivalently, unsigned's); THEY ARE NOT ARRAYS; [emphasis mine] they do not have addresses, so the & operator cannot be applied to them. Arrays must be addressible; bit fields are not addressible; and therefore there are no arrays of bit fields, nor are there bit fields of arrays. As for solving the original problem---obtaining the equivalent of `packed array [0..31] of boolean'---you will probably have to make do with macros, e.g.: #define BIT(name, index) ((name) & (1 << (index))) #define BIS(name, index) ((name) |= 1 << (index)) #define BIC(name, index) ((name) &= ~(1 << (index))) You can, at this point, dispense with the union: typedef long newtype; is probably the best way to go: it is even portable to 16-bitters. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1516) UUCP: seismo!umcp-cs!chris CSNet: chris@umcp-cs ARPA: chris@mimsy.umd.edu