Hi
Although I don't see any problem in the code, I would suggest more
transparent (and faster) coding such as following
UxoAppInfoType *appInfo = ... ;
UxoAppInfoType *nil = 0 ;
int i ;
UxoDataFieldType field = { 1, 0 } ;
for (i = 0; i < NUM_FIELDS; i++)
{
DmWrite( appInfo, (UInt32)(nil->fields+i), &field,
sizeof(UxoDataFieldType) ) ;
}
There should not be any alignment problems, but you can easily convince
yourself: Open memory window (CW/menu/data/view memory) on the appInfo
address and step through the loop while checking the changes in the memory
window.
Jan Slodicka
----- Original Message -----
From: "David Beers" <[EMAIL PROTECTED]>
> However still I have a problem with the same block of code that has been
> stumping me. Referring to the structures below that I'm using for working
> with my AppInfo block, I have a problem when writing to the array of
> UxoDataFieldType structures. The code compiles and the AppInfo block is
> generated without runtime error, but the alignment of the data is off.
> Here's a (somewhat simplified) snippet from the code I am using to write
> that array to the AppInfo block (all the expressions in CAPs are #defined
> constants):
>
> UInt16 stringP, zeroSizeP, fieldCount;
> UxoAppInfoType *appInfo, *nil = 0;
>
> fieldCount = (UInt16)NUM_FIELDS
> stringP = (UInt16)STRING; // *** note:STRING is #defined as 1 ***
> zeroSizeP = 0
>
> for (i = 0; i < fieldCount; i++) {
> DmWrite(appInfo, (UInt32) &nil->fields[i].dtype, &stringP,
> sizeof(appInfo->fields[i].dtype));
> DmWrite(appInfo, (UInt32) &nil->fields[i].dsize, &zeroSizeP,
> sizeof(appInfo->fields[i].dsize));
> }
>
> What is happening is that inside the two-byte unsigned integer member
dtype
> the bits appear to be shifted a byte to the left. Don't know if I'm
> describing this correctly, so I'll show you what it looks like when I read
> the AppInfo block in hex:
>
> Instead of: 00 01 (for dtype = 1)
> I'm getting: 01 00 (which = 256... wrong answer!)
>
> Can any of you see the problem?
>
> On a similar note I'd like to ask: is there something about the AppInfo
> block that makes these alignment issues especially tricky? I notice that
> the SDK sample applications all have reserved unused members in their
> AppInfo structures that have comments like "// from the compiler word
> aligning things [sic]". I also found that an alignment problem I had with
> two UInt8 members in my AppInfo structure was fixed when I changed them to
> UInt16. Does everything have to fall on a two-byte boundary? I haven't
> found official documentation about this issue, but I'm guessing that once
> again it has something to do with me needing to deepen my understanding of
> C.
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/