This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
structure alignment question
- From: "mohanlal jangir" <mohanlaljangir at hotmail dot com>
- To: "eCos Discussion" <ecos-discuss at sources dot redhat dot com>
- Date: Fri, 6 Feb 2004 11:15:15 +0530
- Subject: [ECOS] structure alignment question
- Reply-to: "mohanlal jangir" <mohanlaljangir at hotmail dot com>
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?
Regards
Mohanlal
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss