One more thing about the bitfield approach (another reason you don't want to use it).
Code:
/*if you decide you are going to do this despite what I've been saying at least you have an example of how */
struct bf {
unsigned short a : 16;
unsigned short b : 16;
unsigned short c : 16;
unsigned short d : 16;
};
Okay, the biggest pitfall here is that the way the bits are ordered is machine dependant. The a member is the first 16 bits on some machines while on others it is the last 16 bits.
In your sample code your structure is already on a 32-bit boundary so you could just do this:
Code:
struct whatever{
unsigned short a, b, c, d;
};
There won't be any additional padding on the structure since it is 64 bits in size. So even on a 64-bit machine you are good to go. On a 16-bit machine this is also okay. So you may want to stick with the simple structure.