470,849 Members | 1,037 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

Organization of Structs

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.
Jun 27 '08 #1
0 883

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by news.microsoft.com | last post: by
1 post views Thread by Steven T. Hatton | last post: by
6 posts views Thread by James Pascoe | last post: by
5 posts views Thread by Bilgehan.Balban | last post: by
61 posts views Thread by Marty | last post: by
29 posts views Thread by Dom | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.