Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!wuarchive!uunet!mcsun!unido!uniol!Ingo.Wilken From: Ingo.Wilken@arbi.informatik.uni-oldenburg.de (Ingo Wilken) Newsgroups: comp.sys.amiga.misc Subject: Re: Bitfields in C Message-ID: Date: 8 May 91 11:21:11 GMT References: <214.2826444A@weyr.FIDONET.ORG> Organization: University of Oldenburg, Germany Lines: 33 David.Plummer@p0.f70.n140.z1.FIDONET.ORG (David Plummer) writes: >Does anyone know how to build an easily- addressable bitfield array in >C? Exactly what I would like to be able to do it this: >struct bits { > unsigned long thebits[31] : 1; >} >which of course is impossible, since C doesn't allow arrays in the >bitfield descriptors. [...] >does anyone have any suggestions? What about this: struct bits { unsigned int thebits:31; }; If you want to set bit 10, you just do something like struct bits i; i.thebits = 0; i.thebits |= (1<<10); and a check if bit 7 is set would be if( i.thebits & (1<<7) ) printf("Yeah!\n"); Hope this helps. Ingo -- Ingo Wilken, CS Student, Univ.of Oldenburg, FRG | "Sie kennen das ja vom Pro- wilken@uniol.uucp (..!uunet!unido!uniol!wilken) | grammieren, man weiss ja Ingo.Wilken@arbi.informatik.uni-oldenburg.de | nicht was die Dinger tun." wilken@uniol.zer IRC:Nobody OL:ingo@faramir +--------------- Prof. Claus