The Palm CPU likes to align structures on word boundaries. So the first 17
chars leaves you at a non-word boundary for the wFieldAttribute word, and an
extra byte (unused) is inserted to align the structure by CodeWarrior or
GCC.
Try this instead:
typedef struct
{
Char cFieldName[16];
Word wFieldAttribute; // start on word boundary
Word wFieldLength;
Char cFieldType;
UChar cFieldDecimal;
UChar ucFieldOffset;
} FIELD_DEF;
And you'll get a nicely packed structure.
==-
John Schettino author of
Palm OS Programming For Dummies, http://schettino.tripod.com
-----Original Message-----
From: Garry Chiang [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, December 21, 1999 8:02 PM
To: 'Palm Developers' Forum'
Subject: sizeof question
Hi all,
This seems basic but somehow I got different answer for it:
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?
Thanks,
garry