Page 88 of the Code Warrior C Compiler Reference
says:
"power Align every field on its natural boundary
. . . .
For example, it aligns a character on a
1-byte boundary and a 16-bit integer on
a 2-byte boundary."
This suggests to me that what I did is safe, but there
could be some gotchas that are not described in this
part of the documentation. Does anyone know of any
such gotchas?
Greg Bungo
[EMAIL PROTECTED]
(630)949-3250 voice
(630)949-3299 fax
-----Original Message-----
From: Roger Chaplin <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
Date: Wednesday, October 27, 1999 11:32 AM
Subject: Re: Structure Alignment
"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]>