[uClinux-dev] structure size ????

Peter Ogilvy petero at cvs.com.au
Sun Mar 2 22:11:32 EST 2003


Hi Thomas,

I had to solve this a little while ago, you might want to
look in the archive for the subject

 Platform independant structs

There was a couple of suggestions made, which fit different
circumstances. The solution I used is below.

Below is an example of a struct which is padded so all the data
is on four byte boundaries. The __attribute((packed)) ensures
that there is no additional padding added by the compiler.

Since pad1 and pad2 may not be correctly aligned (depending
on where the code is running) you cant use them. You have to
chose the padding size so the data can be accessed on both
platforms.

Hope this helps

typedef struct
{
    __u32 data1;
    __u8 data2; 
    __u8 pad1;    // padding to preservefour byte alignment dont use
    __u16 pad2;
    __u32 data3;
}
__attribute((packed)) your_struct;


thomas chen wrote:
> i have a structure that is 10 bytes long... on the target side
> (arm) arm-elf-gcc expand that to multiple of 4, ie 12 bytes...
> but on the intel pc side, it is still 10 bytes...  any way to pack
> the structure but without violating the arm alignment problem...
> ie if the structure is 9 byte long, i want to pack it to 10 instead
> of just 9....
>
> thanks
> _______________________________________________
> uClinux-dev mailing list
> uClinux-dev at uclinux.org
> http://mailman.uclinux.org/mailman/listinfo/uclinux-dev
> This message was resent by uclinux-dev at uclinux.org




More information about the uClinux-dev mailing list