You have to be careful casting to non-byte sized variables since the bytes
that you pack into the record are not necessarily word aligned. You will get
an error if you try to cast a non-word aligned address to a UInt16.

Use MemMove to move the bytes to your variable.

Matt

BTW, this turned out not to be a stupid question.

----- Original Message -----
From: "William Chow" <[EMAIL PROTECTED]>
To: "Palm Developer Forum" <[EMAIL PROTECTED]>
Sent: Friday, October 04, 2002 9:18 AM
Subject: Re: Converting to UIn16


> You do the same thing as you did for the byte , you cast it as an unsigned
> short.
> So just replace 8 with 16. Read up on casting in K&R and the C FAQ (found
> online). Should be pretty obvious.
>
>
> ----- Original Message -----
> From: "Grosch, Scott" <[EMAIL PROTECTED]>
> To: "Palm Developer Forum" <[EMAIL PROTECTED]>
> Sent: Thursday, October 03, 2002 1:31 PM
> Subject: Converting to UIn16
>
>
> > OK, sorry for the stupid question here, but....:
> >
> > Let's say I write a record like this:
> >
> > UInt16 someNum;
> >
> > DmStrCopy(record, 0, str);
> > DmWrite(record, StrLen(str) + 1, &someNum, sizeof(someNum));
> >
> >
> > When I read it back, I'd do:
> >
> >
> > Char *record = (Char *) MemHandleLock(h);
> > record += StrLen(record) + 1;
> >
> > Now record is at the offset where that UInt16 was written.
> > How do I grab that value back into a UInt16?  I've always just
> > had a UInt8 before, so I'd just say:  UInt8 n = (UInt8) *record;
> >
> > a UInt16 is two bytes though, so that's not going to work.  Sorry for
> > such a simple question, but I've left my book at home so I can't consult
> > it.
> >
> >
> > --
> > For information on using the Palm Developer Forums, or to unsubscribe,
> please see http://www.palmos.com/dev/support/forums/
> >
> >
>
>
>
> --
> For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/
>


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to