This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: structure size


> ----------------------------------------------------------------------------
> struct xyzzy {
>     short   a;
>     int     b;
> } __attribute__((packed));
> 
> struct xyzzy data;
> 
> int
> fred(void)
> {
>     data.b  = 42;
> }
> ----------------------------------------------------------------------------
> 
> Compile with arm-elf-gcc -S. The assignment to data.b is implemented
> using four separate strb instructions, as I would expect. If you try
> reading data.b instead there will be four ldrb instructions plus
> appropriate manipulation.

Very interesting.  I don't have arm-elf-gcc handy, but I'll
certainly take your word for it.  I swear that didn't used 
work.  The last time I had an alignment problem on ARM was
probably 4 years ago with gcc 2.something.  I distinctly
remember having to change a bunch of "int" assignments into
memcpy() calls when filling in fields in a network packet.

> I don't have a sparc-elf compiler handy at the moment so
> cannot check that, but certainly arm-elf-gcc seems to do the
> right thing.

I stand corrected, and I wouldn't be surprised if recent
versions of SPARC gcc "do the right thing" as well.  It was
even more than 4 years ago when I ran into the problem on SPARC
using a program originally written on a 68K platform -- it had
packed structs with "float" fields that generated bus faults on
a SPARC.

-- 
Grant Edwards
grante@visi.com

-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]