"Phong Nguyen" <[EMAIL PROTECTED]> wrote in message
news:74740@palm-dev-forum...
>
> Thanks for the answers so far but if there is no
> solution for this issue, it would really be a SERIOUS
> problem for me and also for everyone out there when
> using the built-in function sizeof(..) !!!!!!! What
> can I do if I want to define several structure types
> defined a structure of a message and try to decode it
> using the structure pointers as follows:

If you read the compiler documentation included with CodeWarrior, you'll
find that in cases like this, you can surround your structure definition
with pragmas to tell the compiler to pack it as closely as possible,
i.e.

    #pragma options align=packed

    struct PackedChars
    {
    };

    #pragma options align=reset

I'd only do this with structure that are all chars.  If you get a
misaligned 16-bit or larger value, you could trigger a bus error.

Note: the size in bytes of the struct, as sizeof returns, will include
any padding at the end.  This is because sizeof can be used to find the
location in memory of an item in an array of structs... in other words

(char *)&foo[n] == (char *)foo + sizeof(foo) * n

if sizeof(foo) didn't include the padding, this equality would not hold.



-- 
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