[uClinux-dev] structure size ????

Fréderic DUBOIS frederic.dubois at synchronic.fr
Mon Mar 3 03:01:24 EST 2003


But.. why do you want your structs be aligned the same way on both
platforms? To be sent over a networking link?

> -----Message d'origine-----
> De : Thomas Chen [mailto:tchen at on-go.com]
> Envoyé : lun. 3 mars 2003 08:26
> À : uclinux-dev at uclinux.org
> Objet : Re: [uClinux-dev] structure size ????
> 
> 
> 
> well.... i saw the archive, but i actually want something
> "in between"....
> 
> the fact that my target is an architecture that the alignemnt
> has to be on 16 bit, i was looking for somethign that would
> pad the structure to 16 bit boundry...
> 
> the closest thing that came to it is
>  -mstructure-pad-boundry =
> 
> but that can only be value of 8 or 32.... not 16... so i
> was wondering what it could be???  your suggestion is good
> but it require software writer to be "architecture aware"...
> and be very conciencious about the structure definition,
> some of the stuff i work with is third party, and i have
> no easy way to check every existing structure... was hoping
> a compiler option to do that dirty work for me...!!!
> 
> 
> 
> on 3/2/03 7:11 PM, Peter Ogilvy at petero at cvs.com.au wrote:
> 
> > 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
> > 
> > _______________________________________________
> > 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
> > 
> 
> _______________________________________________
> 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