bitfield advantages

From: Jaco van Iterson (J.C.vanIterson@ET.TUDelft.NL)
Date: 03/08/96

On Thu, 7 Mar 1996, Hades wrote:
> Now I've heard a lot about bitfields recently but I'm mnot exactlyu sure
> what iut is they do. Can someone let me know what advantage bitfields have
> over bitvectors?

Well this are the advantages I can think of:
- Bitfield structures don't have the 32 bit limit, you can have as much bits
as you like.
- The names of the bits don't have to be special for the whole code,
they only need to be special within the bitfield itself, so two different
bitfield structures can have the bit 'humming' on different positions without
- Bitfield acces looks nicer in the code, a bitfield acces looks something like
"if (ch->affection.blind) {" instead of "if (ch->affections | AFF_BLIND) {"
the declaration looks like:
#define BIT(a) unsigned a: 1            /* only 1 time in the code */
struct bitfield {
instead of
#define VECTOR_BIT1;
#define VECTOR_BIT2;
#define VECTOR_BIT3;
#define VECTOR_BIT4;
int bitvector;
- Bitfields probebly are a little bit faster

I  think the fist advantage is the biggest one.

A disadvantage is:
It's a bit more difficult to make bitfields 100% sure to be portable to all

I hope this helps


This archive was generated by hypermail 2b30 : 12/07/00 PST