Garry,

At 12:01 PM 12/22/99 +0800, you wrote:
>typedef struct 
>{
>   Char        cFieldName[16];
>   Char  cFieldType;
>   Word        wFieldAttribute;
>   Word        wFieldLength;
>   UChar cFieldDecimal;
>   UChar ucFieldOffset;
>} FIELD_DEF;
>
>I sizeof all the structure members and it returns me 23.
>sizeof(FIELD_DEF) will return me 24 bytes, instead of 23.
>Why is it so? Where does the one extra byte come from?

What is happening here is that the compiler is aligning the attributes on
word boundaries.  Since cFieldName is 16 bytes, cField starts on byte 16 as
you'd expect.  If there was another char after cFieldType, it would start
on byte 17 as expected.  But the next attribute is a word, so the compiler
moves it so it doesn't cross a word boundary, and it begins at the byte 18.
 (Remember that the first byte is byte 0).

Hope this helps.

Greg

Greg Winton
Bachmann Software and Services, LLC
mailto:[EMAIL PROTECTED]
http://www.bachmannsoftware.com

Reply via email to