>> That would be a judgement call, I wouldn't do it. There are a limited
> set of circumstances where such spacesaving will actually make any
> difference in comparison to the amounts of data generally being moved
> around. The only place I use bitfields is to interface with something
> that is already playing such games. The word spec for instance is a good
> example of a data format which does that, and theres certainly loads of
> hardware which sets individual bits and bit ranges which are easier
> handled with bitfields rather than explicit shifting and masking
>> Someone else said that bitfields are not standard, there are indeed
> Though ansi allows only int, unsigned int, or signed int type. So
> technically no char i:3; or long i:3;
K&R second edition seems to disagree (p212). "A structure member may also
consist of a specified number of bits. Such a member is also called a
bit-field, or merely field; its length is set off from the declarator for
the field name by a colon."
It also says "The ANSI standard makes fields even more
implementation-dependent than did the first edition. It is advisable to read
the language rules for storing bit-fields as "implementation-dependent"
without qualification." - which sounds to me like a good reason to avoid
them if possible, unless you can be certain that you are using the same
compiler as the people who wrote the system to which you are interfacing.
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!