[ECOS] structure alignment question

mohanlal jangir mohanlaljangir@hotmail.com
Fri Feb 6 05:48:00 GMT 2004


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



More information about the Ecos-discuss mailing list