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]

structure alignment question


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


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