Re: C question
- From: "David T. Ashley" <dtashley@xxxxxxx>
- Date: Wed, 27 Jul 2005 23:30:19 -0400
> Do not use bit fields in C. From page 150 of the second
> edition of Kernighan and Ritchie, "The C Programming
> Language", ISBN 0131103628:
Yes and no.
Some processors offer "near" and "far" memory. Typically (as is true for
the 68HC08 and TMS370C8 cores) bitfield operations on bitfields of size 1
which are in "near" memory come down to a single machine instruction (a
direct-addressed OR, AND, or BTBC instruction). Using a bitfield of size 1
on these machines is vastly superior to a variable declared outside a
structure.
Generally, the breakdown is:
a)Bitfields of size 1 in near memory on small machines often work well.
b)Bitfields of size 8 or UCHARS on more powerful machines often work well.
c)Bitfields of other sizes have questionable value in embedded work. The
code to extract and pack the fields is often bulky.
However, on larger machines, as long as one understands the tradeoffs,
bitfields of unusual sizes can be useful. For example, if I were
implementing chess on a PDA and had to build a large game tree in limited
RAM, I would pack things, knowing that I would make the game tree smaller at
the expense of size and speed of the code that deals with it.
.
- References:
- C question
- From: Xarion
- Re: C question
- From: Colin Paul Gloster
- C question
- Prev by Date: Re: Tiny ARM Development
- Next by Date: Re: 486 pll
- Previous by thread: Re: C question
- Next by thread: Re: C question
- Index(es):
Relevant Pages
|