All things must be divisible into even bytes which is why an array of 2 bit structures will take the same space as an array of 1 byte structures, the machine can only address bytes. Rock2000 did hit on something though, without optimization a declaration like:
struct x
{
int xflags:3;
int count;
int yflags:2;
};
would take AT LEAST 6 bytes (even though it could be rewritten to fit in 5), and on some platforms it would actually have to be padded to TWELVE bytes, because often ints must be aligned on addresses divisible by
four.
Even if the struct was rewritten, it would still take 6 or 8 bytes due to the alignment rules for ints. The general rule is, worst case, data must be aligned on a boundry that is divisible by its size (so on 64 bit platforms pointers must be aligned on 8 byte boundries).
If your curious...just use sizeof(tagTile) without manually adding the nPadding field and you'll see what pading the compiler will force on you anyway.
Another note...this pading occurs no matter wheither you declare arrays of the struct, or just one, because the compiler must compute the sizeof() value...and the value can't change arbitrarily from one module to the next...so be careful to turn the compiler's pading on or off for ALL of your modules, or you won't be able to link them.
[This message has been edited by Xai (edited October 17, 1999).]