Thanks for the help. I am a java programmer with little expereince shifting
bits and doing things at that low level. I would very much like to
understand the code before I use it though. I assume that
range->startRange = *s++ & 0x000000FF;
puts the first byte into range->startRange at the right most position? is
this right? does doing
range->startRange <<= 8;
shift it so that I can do
range->startRange = *s++ & 0x000000FF; to write the next one in??
Am I right in understanding how it works? I do this 4 times, one for each
byte right?
>From: Marshall Clow <[EMAIL PROTECTED]>
>Reply-To: "Palm Developer Forum" <[EMAIL PROTECTED]>
>To: "Palm Developer Forum" <[EMAIL PROTECTED]>
>CC: "Salma Saad" <[EMAIL PROTECTED]>
>Subject: Re: problem reading integers
>Date: Tue, 4 Sep 2001 14:00:14 -0700
>
> >What you suggested makes a lot of sense and I think it should work. It
>still doesn't work for me though, am I doing something else wrong as well?
>Now I get the following error
> >
> >"application1.0 just read from memory location 0x10024AA7 causing an
>address error. An address error means that the application accessed a 2 0r
>4 byte value at an odd (not even) memory address"
> >
> >I changed my unpack routine to:
> >
> >static void UnpackRange(Range* range, const PackedRange *packedRange)
> >{
> > const char *s = packedRange->name;
> >
> > range->name = s;
> >(1) s += StrLen(s) + 1;
> >(2) range->startRange = *((Int32*)s);
> > s = s + 4;
> > range->endRange = *((Int32*)s);
> >}
>
>Suppose that s starts out at 0x20000.
>Suppose that the first 7 bytes are "Hello!\0"
>After the line marked (1), s will be 0x20007
>the line marked (2) will bomb, because you are reading 4 bytes from an odd
>address.
>
>You have to read the 4 bytes on at a time, and assemble the long yourself.
>
> range->startRange = *s++ & 0x000000FF; range->startRange <<= 8;
> range->startRange |= *s++ & 0x000000FF; range->startRange <<= 8;
> range->startRange |= *s++ & 0x000000FF; range->startRange <<= 8;
> range->startRange |= *s++ & 0x000000FF;
>
>
>--
>-- Marshall
>
>Marshall Clow Idio Software <mailto:[EMAIL PROTECTED]>
>Hey! Who messed with my anti-paranoia shot?
>
>--
>For information on using the Palm Developer Forums, or to unsubscribe,
>please see http://www.palmos.com/dev/tech/support/forums/
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/