This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: structure alignment question
- From: Gary Thomas <gary at mlbassoc dot com>
- To: mohanlal jangir <mohanlaljangir at hotmail dot com>
- Cc: eCos Discussion <ecos-discuss at sources dot redhat dot com>
- Date: Thu, 05 Feb 2004 23:05:20 -0700
- Subject: Re: [ECOS] structure alignment question
- Organization: MLB Associates
- References: <LAW11-OE19kvV3lRREd00051522@hotmail.com>
On Thu, 2004-02-05 at 22:45, mohanlal jangir wrote:
> I have some questions regarding structure alignment. If I declare a
> structure like
>
> struct structure {
> unsigned short a;
> unsigned char b;
> unsigned char pad[1];
> };
>
> and then same structure like
> struct structure {
> unsigned short a;
> unsigned short b;
> };
>
> Are both declaration free from alignment problem for any kind of access or
> it's only later one?
>
> Another question is, if I have a structure like
> struct structure {
> unsigned int a;
> unsigned short b;
> unsigned char c;
> };
>
> struct structure temp;
> unsigned int *p = &(temp.a);
> unsigned short *q = &(temp.b);
> unsigned char *r = &(temp.c);
>
> Do all pointers (p, q and r) need to be 4 byte boundary aligned or p at 4
> byte boundary, q at 2 byte boundary and r at 1 byte boundary will do?
The answers you seek are architecture (and even ABI) dependent. You
should ask on the GCC list to get authoratative answers.
--
Gary Thomas <gary@mlbassoc.com>
MLB Associates
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss