Mail Archives: djgpp/2000/01/07/08:11:18
>Rob McCrea (r_mccrea AT hotmail DOT com) wrote:
>: My expression won't recognize the overflow...
>:
>: while ((s+1) > s) s++;
>:
>: is an infinite loop. What's up with that?
>: Apparently the condition is being evaluted as (1>0).
>: That's not right is it? I'm compiling with gpp -Wall testsize.cpp -o
>: testsize.exe.
>:
>: Please, can someone explain why its not acting like a computer?
I'm not sure exactly what you're claiming is wrong here, but you might not
realise that sooner or later, given that 's' is likely an integer of some
size or another, it'll wrap around, and your loop will exit. For example, if
's' is an unsigned char you will loop until s = 255, then s+1 will be 256
which overflows and wraps round to 0. (0 > 255) is false, and you'll exit
the loop.
Chris
- Raw text -