Vincent <vincent.catros_NO_SPAM_@bigfoot.com> wrote:
Hello!
I have some trouble using qcc.
I have a struct looking like:
typedef struct {
unsigned int ID;
unsigned char Mode;
unsigned char Data[8]; /* 8 is only an exemple */
} MyType;
Having some trouble passing this struct to a driver of my own, I have looked
to sizeof(MyType) which equal 16. So, I first thought to 32 bits alignement
feature (4 bytes for ID, 1 byte + 3 dummy bytes for Mode and 8 bytes for
data.
But, I saw that &Data == (&Mode + 1) ) which means a 8bits alignement.
Do you have any idea?
Since Data is “unsigned char”, it actually goes to:
4 bytes ID, 1 Bytes Mode, 8 bytes Data, 3 bytes pad
If Data is a “unsigned int”, then, since it have to start
on int alignment address, it goes to:
4 bytes ID, 1 Bytes Mode, 3 bytes pad, 4 byte Data
The same, if Data is a “short”, then, it goes to:
4 Bytes ID, 1 Bytes Mode, 1 byte pad, 2 byte Data
As others suggest, you can pack them if you want,
(but make sure you do the right thing. If you put
an int on unalignment address, some CPU will sigbus
you).
-xtang
Thanks
Vincent