[uClinux-dev] structure size ????

Fabio Giovagnini fgiovag at tin.it
Mon Mar 3 06:12:54 EST 2003


According my knowledge there are two aspects:
1) the alignment capability of yuor microprocessor. You should know if you can 
align a word to an odd address or if you can align a long word to an address 
that isn't multiple of 4. On my microcprocessor (hitachi h8300h,h8s, sh2,sh3) 
this is not possible so you cannot align:
struct _uuu {
	usigned long a1;
	unsigned char a2;
	unsigned short a3;
} uuu;
because a3c in on an odd address and for my micro it is not allowed;

2) soem version of gcc have a bug about the use of __attribute__((packed)). 
The behaviour changes if you write:
struct _uuu {
	usigned long a1;
	unsigned char a2;
	unsigned short a3;
} uuu __attribute__((packed)); // works

typedef struct _uuu {
	usigned long a1;
	unsigned char a2;
	unsigned short a3;
} uuu __attribute__((packed)) uuu_t; // I'm not sure but I suppose it works

typedef struct _uuu {
	usigned long a1;
	unsigned char a2;
	unsigned short a3;
} uuu uuu_t __attribute__((packed)) ; // I'm pretty sure it doesn't works


Regards.

Alle 09:01, lunedì 3 marzo 2003, Fréderic DUBOIS ha scritto:
> 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
>
> _______________________________________________
> 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