This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: Data alignment with gcc
- To: David Korn <dkorn at pixelpower dot com>, Tim Jackson <tim at timj dot co dot uk>, gcc-help at gcc dot gnu dot org
- Subject: RE: Data alignment with gcc
- From: "Lewin A.R.W. Edwards" <larwe at larwe dot com>
- Date: Fri, 30 Mar 2001 08:54:42 -0500
> As long as the class doesn't use virtual inheritance or virtual
>functions, there should be no additional data hidden in the struct IIRC.
Just my experience thus far...
>C++ isn't all that uncommon in embedded work but you do need to have
It isn't unheard of, I was just commenting as an aside that I haven't
tested this issue with C++ because I work much more frequently with C. I've
seen a figure thrown about in some embedded systems periodicals that 70% of
embedded apps are mixed C/asm.
> >// Master Boot Record
> >typedef struct {
> > unsigned char fill[0x1be]; // boot code
> > PARTENTRY partitions[4]; // partition table
> > unsigned char sig_55; // 55h boot signature
> > unsigned char sig_aa; // AAh boot signature
> >} __attribute__((packed)) MBR, *PMBR;
> >
> >Works in 2.95.2.
>
> I have sometimes heard it said that the __attribute__ ((packed)) needs
>to be put on the data members of a struct as well, i.e.
The above syntax is working well for me in-circuit, so it may depend on
what the data members are (i.e. if they are also structures, they need to
be packed also), and it could well depend on the target architecture too
(my code is compiled for arm-elf). My PARTENTRY structure is defined as a
packed structure, so I didn't explicitly re-specify to pack it there.
There is an issue - which someone was complaining about either here in
gcc-help or in ecos-discuss recently - about the difference between packing
and alignment. I think the poster was having problems with a structure he
wanted to be both packed and aligned. However I haven't yet been bitten by
such an issue (and I set up an MMU exception handler in my target
specifically to catch this problem).
=== Lewin A.R.W. Edwards (Embedded Engineer)
Work: http://www.digi-frame.com/
Personal: http://www.zws.com/ and http://www.larwe.com/
"Und setzet ihr nicht das Leben ein,
Nie wird euch das Leben gewonnen sein."