"Greg Bungo" <[EMAIL PROTECTED]> wrote:
> I'm porting a program from another platform to Palm,
> and I encountered a structure alignment problem.  The
> default Palm CodeWarrior alignment is "68K".  This
> will make the size of a structure such as this
> 
> typedef struct tagHDR
> {
> char    Type[2];
> char    ID[8];
> char    Num[5];
> char    Time[6];
> } HDR;
> 
> 22 bytes rather than the expected 21 bytes.
> I changed the Struct Alignment setting in
> CodeWarrior to "PowerPC", and now this
> structure is 21 bytes.  This saves me from
> rewriting some of our code, since there are places
> in the program that depend on sizeof(HDR).
> 
> My question:  will this change of the alignment
> setting cause problems on the Palm?  If there
> is no known reason why the "68K" alignment
> type is needed, I would prefer the PowerPC
> setting, since that will save us a few bytes,
> and memory on the Palm is very precious.

If the structure you show above is the only one, then no, it won't 
cause problems. However, regardless of the compiler settings, the 
MC68000 core CPU that's in the DragonBall requires even addresses when 
accessing data that is 16-bit or longer. Maybe a CodeWarrior expert 
needs to jump into this to explain exactly what PowerPC alignment does 
to that compiler (it obviously packs char data, but how does it align 
16-bit or longer data types?). If PowerPC alignment does remove all 
padding, then something like

struct foo
{   char a[5];
    int  b;
};

would give you an address error when you try to access the b element.

--
Roger Chaplin
<[EMAIL PROTECTED]>

Reply via email to