Classic 'C' issue:

        UInt32  baseOffset = 4000000;
        UInt32  testOffset = baseOffset + (30000 * 4);
should be
UInt32 baseOffset = 4000000L; // the 'L' isn't necessary here, but good to use
        UInt32  testOffset = baseOffset + (30000L * 4L);    // need the 'L'

Roger Stringer

At 02:15 AM 11/12/2006, you wrote:
Subject: Re: Unexpected addition results
From: Don Albertson <[EMAIL PROTECTED]>
Date: Sat, 11 Nov 2006 10:09:21 -0500
X-Message-Number: 6

Lynn Allan said (on or about) 11/11/2006 09:46:
> UInt32  baseOffset = 4000000;
> UInt32  testOffset = baseOffset + (30000 * 4);         // 3988928
> testOffset = baseOffset + ((UInt32)30000 * (UInt32)4); // 4120000
> testOffset = baseOffset + (30000L * 4L);               // 4120000
>
> I'm using CW9.3 and seeing unexpected results when adding constants. I would expect the 2nd, 3rd, and 4th statements to all result in testOffset being set to 4,120,000, but the 2nd statement seems to treat the (30000*4) as Int16 numbers, and it becomes a negative number.
>
> Is this a bug, or defined/expected behavior? Or am I confused?
>
> This has thrown me off several times. Is there a setting to cause constants to be treated as Int32?
>
>


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

Reply via email to