• Advertisement

Archived

This topic is now archived and is closed to further replies.

Can You Help Me?

This topic is 5831 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In VC I have:
  
typedef struct 
{
	BYTE a;
	WORD b;
	WORD c;
	BYTE d[11];
}TAL;
TAL t;
  
And when I write: sizeof(BYTE) it returns 1 sizoef(WORD) returns 2 So, I think, sizeof(TAL) must be 1 + 2 + 2 + 11 = 16 But, when I write sizeof(TAL) it returns 18! why???

Share this post


Link to post
Share on other sites
Advertisement
struct padding........it is an option you can turn off in msvc.
it is something like an efficiency issue where the compiler will add a few extra bytes so that the cpu likes it more.

"I pity the fool, thug, or soul who tries to take over the world, then goes home crying to his momma."
- Mr. T

Share this post


Link to post
Share on other sites
Word-alignment.

The first BYTE requires an entire word to store (2 bytes), while the array of 11 bytes also requires an extra byte to keep the structure word-aligned. You can change the alignment, but I wouldn''t recommend that at your current stage.

Don''t worry, it''s normal.

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!

Share this post


Link to post
Share on other sites

  • Advertisement