First, thanks to Bob Withers who wrote:
"Reverse the order of the struct definitions and make sure that NUM_FIELDS
is defined as a compile time constant."
Reversing the struct definitions did it, thanks! Learn something new every
day.
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.
TIA for your help!
David Beers
----- Original Message -----
From: "David Beers" <[EMAIL PROTECTED]>
To: "Palm Developer Forum" <[EMAIL PROTECTED]>
Sent: Wednesday, May 28, 2003 7:22 AM
Subject: Nested structure does not compile
> I have an AppInfo block for which I'm trying to use the UxoAppInfoType
> structure listed below. Notice the last member of the structure is an
array
> of structures of UxoDataFieldType (also listed).
>
> typedef struct {
> UInt16 renamedCategories; // bitfield of categories with a different
> name
> char categoryLabels[dmRecNumCategories][dmCategoryLength];
> UInt8 categoryUniqIDs[dmRecNumCategories];
> UInt8 lastUniqID; // Unique IDs generated by the device are between
> // 0 - 127. Those from the PC are 128 - 255.
> UInt8 reserved1; // from the compiler word aligning things
> UInt16 reserved2;
> UInt16 sortOrder; // Current sort order for database
> UInt16 syncPref; // to set sync type from handheld
> UInt16 numDataFields;
> char dataSourceName[dsnLength];
> char ownerInitials[4];
> UxoDataFieldType fields[NUM_FIELDS];
> } UxoAppInfoType;
>
> typedef struct {
> UInt16 dtype;
> UInt16 dsize;
> } UxoDataFieldType;
>
> This does not compile in CW 8.3. The compiler chokes on that last member
of
> my UxoAppInfoType, saying it expects a semi-colon here (after fields):
>
> UxoDataFieldType fields [NUM_FIELDS];
> ------------------------^
>
> If I pull this array out of the UxoAppInfoType and just declare it as a
> global on its own it compiles fine.
>
> Can someone explain the reason for the compile error? Is is my ignorance
of
> C or a limitation of the the compiler or???
>
> Thanks!
> David Beers
>
>
>
>
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/