Prevent compiler padding structures out to WORD boundaries
Hi,
If you have a structure that is an odd number of bytes (say 7 bytes), the compiler will probably add 1 byte to pad it out to 8bytes (so the sizeof() function will return the structure size as 8 bytes). 99.99% of the time this is ok. Is there a compiler driective I can insert in the structure definition if I want sizeof() to return the as_desgined number of bytes(in this particular example 7 bytes)? |
You can use __attribute((packed)). Why do you want to do this? There really aren't very many good reasons.
|
it's just that i'm messing about with usb - and at some points the devices returns data which is consecutive structures end to end - and they are not an even number of bytes each.
So my pointer arithmetic gets messed up if you get what I mean. |
Okay, that's what I thought. Do you use bitfield structures? Not only does it do what you want, but it also isn't vulnerable to the various definitions of integer types.
|
All times are GMT -5. The time now is 07:11 AM. |