bitfields considered harmful?

Art Boyne boyne at hplvli.HP.COM
Fri May 5 00:51:27 AEST 1989


>sme at computing-maths.cardiff.ac.uk (Simon Elliott) writes:
>In article <1473 at uwbull.uwbln.UUCP>, ckl at uwbln.UUCP (Christoph Kuenkel) writes:
>> I like [bitfields] 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.
>
>Well, you may be right about readability, but I don't think you'll find that
>you've saved much space in your program.  Oh, you might save it in the
>source, but the same shifting and masking is going on under the hood.

Whoa!  Whether or not the shifting and masking takes place depends on the
processor you are running on.  With the 68000, single bit bitfields can
be handled with the BCLR, BSET, BCHG, and BTST instructions.  The 68020
has a set of multi-bit bitfield instructions for insertion, extraction,
and testing.

PS. I know that, internally, the processor is still doing shift/mask, but
it isn't taking up my code space!

Art Boyne, boyne at hplvla.hp.com



More information about the Comp.lang.c mailing list