At 4:21 PM +1000 4/9/01, James Nicholls wrote:
>Hi all, I've got a structure defined in CodeWarrior C++ as:
>
>struct T
>{
>  UInt32 f1 : 24;
>  UInt8  f2;
>};
>
>This structure is meant to treat the first three bytes of memory as a unit
>and the following byte as another unit inside of a 4 byte word.  sizeof(T)
>== 6.  WHY DOESN'T EQUAL 4!!??

Because integer fields of structures prefer to align themselves on natural 16-bit or 
32-bit word boundaries. If you don't want this behavior, and instead want each field 
to use only the number of bits you've defined, use   #pragma options align=packed   
before the structure definition and   #pragma options align=reset   afterwards.

Regards,

Jim Schram
Palm Incorporated
Partner Engineering


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to