P
pradeep
Hello friends,
If we have a struct definition like this
typedef struct s {
char a;
int b;
char c;
} _s;
where because of alignment effects the layout given results in memory
inefficiency, do we need to manually arrange things (char then char
then int) or will a good optimizing compiler automatically reorder the
fields in the struct?
Also if we do arrange it as char then char then int, the first dword
in the struct will have two char bytes and two padding bytes. How will
the compiler organize the space and why? Will it be
padding - padding - char - char
or padding - char - padding - char
or char - char - padding - padding
etc.?
Thanks.
If we have a struct definition like this
typedef struct s {
char a;
int b;
char c;
} _s;
where because of alignment effects the layout given results in memory
inefficiency, do we need to manually arrange things (char then char
then int) or will a good optimizing compiler automatically reorder the
fields in the struct?
Also if we do arrange it as char then char then int, the first dword
in the struct will have two char bytes and two padding bytes. How will
the compiler organize the space and why? Will it be
padding - padding - char - char
or padding - char - padding - char
or char - char - padding - padding
etc.?
Thanks.