From: sparhawk AT eunet DOT at (Gerhard Gruber) Newsgroups: comp.os.msdos.djgpp Subject: Re: enum problem Date: Wed, 17 Jun 1998 23:20:29 GMT Organization: Customer of EUnet Austria Lines: 49 Message-ID: <358d472e.3524128@news.Austria.EU.net> References: <358745c4 DOT 10851789 AT news DOT Austria DOT EU DOT net> NNTP-Posting-Host: e056.dynamic.vienna.at.eu.net Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Destination: sl AT psycode DOT com DOT NOSPAM (Gili) From: Gruber Gerhard Group: comp.os.msdos.djgpp Date: 17 Jun 1998 14:18:48 GMT: >On Mon, 15 Jun 1998 18:31:52, sparhawk AT eunet DOT at (Gerhard Gruber) >wrote: > >> usually) or, if you want to use the enum only as bits then you could use >> bitfields. This way you can identify each value and you don't have to bother >> to or them together (or and them apart). > > Tell me more about these bitfields and provide an example if >possible. Thank you, typedef struct { UBYTE InUse : 1; // Set when an irq is allocated UBYTE Opened : 1; // port is opened UBYTE Transfer : 1; // transfer in progress UBYTE IOMode : 1; // TRUE = Reading, FALSE = writing UBYTE Error : 1; // error indicator } SerState; You can define more bits if neccessary, I just happend to use 1 per Value. I recommend to use unsigned char for bitfields because this way the total size of the structure is just as big as necessary to hold all the bits (in this case 1 byte). If you use unsigned int then the minimum size the structure can be is the size of an int. I recomment to use unsigned types though, because a single bit would represent 0 or -1 instead of 0 or 1 and this might be confusing. The usage is simple. Just like any other structure with "normal" types. i.e.: SerState st; st.InUse = TRUE; ... if(st.InUse == TRUE) do something; -- Bye, Gerhard email: sparhawk AT eunet DOT at g DOT gruber AT sis DOT co DOT at Spelling corrections are appreciated.