Mail Archives: djgpp/1998/06/18/03:15:35
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.
- Raw text -