Well, I think Phong, that same problem I have also faced.
Well, try this one
typedef struct
{
UInt8 Flag1;
UInt8 Flag2;
Char MyNumber[19];
}First;
typedef struct
{
UInt8 Flag1;
UInt16 MyID;
float Qty;
Char MyNumber[19];
}Second;
Everything above is right. I was able to write my records using both these
two structures in their respective databases. I could see all the entries in
the record location using DBViewer. I was very happy [Short happiness, I
must say]
Then I tried to read all records using First and Second Structures. With
First I got it right. Again I was very happy I thought my code is *bug*
free.
Then I tried to read records using Second Structures. And What I got was
totally unexpected.
I could read, Flag1, MyID and Qty. But while reading MyNumber using Second
Structures. My Program started reading from (1+2+4 + ?? ) i.e. 8 position,
while I was expecting it to read from 7th [I am referring to ZERO based
indexing here].
I think, here even bit ordering came into picture in that case because when
in Second structure I changed UInt8 to UInt16 everything worked fine [After
some recoding].
Atul
----- Original Message -----
From: "Phong Nguyen" <[EMAIL PROTECTED]>
To: "Palm Developer Forum" <[EMAIL PROTECTED]>
Sent: Saturday, January 26, 2002 9:29 AM
Subject: Re: Code Warrior Compiler bug?
> What I want to do is:
>
> char buffer[100];
> char* message = buffer;
> int index = 0;
> buildHeader (&message[index]);
> index += sizeof(HeaderType);
> assembleData (&message[index]);
> index += 10;
> buildTrailer (&message[index]);
> index += sizeof(TrailerType);
>
> and return index as the size of the built message. As
> you can see if sizeof (..) does not return the correct
> value, it would mess up the content of the message and
> also the return size. Of course, I can use 3 instead
> of sizeof(HeaderType) or so but this is not really a
> good programming practice since I may want to change
> the structure of HeaderType and TrailerType later. On
> the other hand I might also want to port existing code
> built in other platforms to Palm OS and so if
> sizeof(..) does not return the correct value ....my
> feeling for CodeWarrior would be "!%$##@!#$%!@#%^$&*"
> .
>
> Regards,
>
> --- Max Bian <[EMAIL PROTECTED]> wrote:
> > What exactly is the problem you have? Accessing the
> > data in the MessageType
> > struct? How is that a problem? Because sizeof()
> > doesn't give you the size you
> > expect? What structure pointers are you talking
> > about?
> >
> > Max
> > --- Phong Nguyen <[EMAIL PROTECTED]> wrote:
> > > 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:
> > >
> > > typedef struct
> > > {
> > > char preamble[2];
> > > char command;
> > > }
> > > HeaderType;
> > >
> > > typedef struct
> > > {
> > > char checksum[2];
> > > char terminator;
> > > }
> > > TrailerType;
> > >
> > > typedef struct
> > > {
> > > HeaderType header;
> > > char data[10];
> > > TrailerType trailer;
> > > }
> > > MessageType;
> > >
> > > Any solution? Thanks.
> > >
> > > --- Joe <[EMAIL PROTECTED]> wrote:
> >
> > ??? words cut off...
> >
> > =====
> > http://www.weirdwww.com/
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Great stuff seeking new owners in Yahoo! Auctions!
> > http://auctions.yahoo.com
> >
> > --
> > For information on using the Palm Developer Forums,
> > or to unsubscribe, please see
> http://www.palmos.com/dev/tech/support/forums/
>
>
> __________________________________________________
> Do You Yahoo!?
> Great stuff seeking new owners in Yahoo! Auctions!
> http://auctions.yahoo.com
>
> --
> For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/tech/support/forums/
>
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/