Evgeny Rokhlin wrote:
> 
> I can't believe my eyes!
> My program (executed on Palm) gave me results, that were different from the
> results of the same program, executed on PC.
> I used debugger and found out, that in this piece of code:
> while( nIndex < nAmount )
>     {
> 
>         .......calculations;
>         nIndex++;
>     }
>     pKey->m_lLastRead += nIndex-1;
> 
> Having nIndex=0 and nAmount=128 the compiler ignored
> {        .......calculations;
>         nIndex++;
> }
> and went straight to the line     pKey->m_lLastRead += nIndex-1;  !!!

If I understand you correctly, you've compiled the program for the
Palm and for your PC, and they act differently. It sounds to me like
on the Palm, nIndex and/or nAmount are signed bytes (8-bit integers),
while on the PC they are 16- or 32-bit integers.

In the Palm case, if nAmount is a signed byte, then setting it
to 128 will in fact set it to -128, and so on the first pass your
code looks like:

while ( 0 < -128 )      /* that would be false, skip to the end */
        {
                ........calculations /* never executed */
                nIndex++;
        }
pKey->m_lLastRead += nIndex-1;  /* the next line executed       */

In fact, (again assuming these are signed bytes) the compiler
might even be smart enough to realise that your loop will never
get executed and just removed it.

Now, I'm not familiar enough with Palm programming to know that
this is the case for certain, but it sure sounds like a classic
case of  the "size of an int problem".

It would probably help if we could see the declarations for
nIndex and nAmount.

Is it possible that the type you declared them as is a signed
type in CW and an unsigned type in the other compiler you used?

> Well, can't I use while() in CW?

That seems rather unlikely.

Jeff
-- 
Jeff Hildebrand                       | Voice: 204-942-2992 ext 250
Symbol Technologies                   | FAX:   204-942-3001
400-123 Bannatyne Ave                 | Email: [EMAIL PROTECTED]
Winnipeg, Manitoba, Canada R3B 0R3    |

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palm.com/devzone/mailinglists.html

Reply via email to