|
|
A bitfield is a way to save data space by packing several objects into a single storage unit. The syntax of field definition and access is based on structures:
struct control { unsigned int control_bits: 5; unsigned int set_bits: 5; unsigned int mod_bits: 3; }Bitfields defined in consecutive order within the structure will, if possible, be packed within adjacent bits of the same integer. Individual fields are referenced just like any other structure members. Fields behave like small integers and may participate in arithmetic expressions just like other integers.
Different compilers use different bitfield conventions for structures, which is why it is often not possible to link files that were generated by different compilers into a single executable file. Code that does not use bitfields is generally easier to port across compilers, but using bitfields makes the code easier to read and maintain.
USL-based compilers allow the vendor to determine many of the bitfield behaviors. In general, the SCO OpenServer 5 compiler usually uses the behaviors that were defined for the Microsoft Compilers used for Open Desktop 3.0 and earlier releases, whereas the SVR5 compiler uses the behaviors that were defined for the SCO SVR5 1 and 2 compilers.
Some known differences in how the SCO OpenServer 5 and SVR5/SCO SVR5 2.0 compilers handle bitfields are:
struct s1 { char c; int bf:24; }; struct s2 { short s; int bf:24; };On the SCO OpenServer 5 compiler, both s1 and s2 are 8 bytes long, and
bf
is offset
4 bytes from the beginning of the structure.
For the SVR5 and SCO SVR5 1 and 2 compilers,
s1 is 4 bytes and bf
starts 1 byte
from the beginning of the structure,
but s2 is 8 bytes, and bf
starts
2 bytes from the beginning of the structure.