bitfields considered harmful?

Christoph Kuenkel ckl at uwbln.UUCP
Thu Apr 27 20:01:38 AEST 1989


We have some software using C bitfields like in

	struct ... {
		unsigned	active : 1,
				waiting : 1;
		...
	};

During various ports of that to different SysV machines (should i have posted
that to comp.unix.wizards?) we ran into problems because of compiler bugs.
One time, assembler code was produced that tried to shift a word 0 bits to the
right (68020), another time bitfields read nonzero all the time (iapx386), as
in
	if (x.active) { /* always done */ } else { /* dead code */ }

Now, are bitfields generally considered harmfull?  Are there other good
reasons to avoid them? what does ANSI C say about it?

I like them cause they save space and are much more readable than 
oriing/anding with # defines and i dont have to bother with questions like
how many flags fit into one int.

thanx, christoph
-- 
# include <std/disclaimer.h>
Christoph Kuenkel/UniWare GmbH       Kantstr. 152, 1000 Berlin 12, West Germany
ck at tub.BITNET                ckl at uwbln             {unido,tmpmbx,tub}!uwbln!ckl



More information about the Comp.lang.c mailing list