On Aug 4, 1:05 pm, Scott Bale <drbceb-t...@yahoo.com> wrote:
> I once got "bit by byte" in the following loop:
>
> for(byte a=Byte.MIN_VALUE; a<=Byte.MAX_VALUE; a++) {
>   for(byte b=Byte.MIN_VALUE; b<=Byte.MAX_VALUE; b++) {
>     byte[] test = new byte[] { a, b};
>     //do something...
>   }
>
> }
>
> When I ran this, CPU shot to 100% and I had to take down Eclipse with
> extreme prejudice. Can you spot the problem?
>
> The problem is, neither of the loops can terminate. Neither for
> condition will ever become false and cause the loop to terminate,
> because neither a nor b can ever grow larger than Byte.MAX_VALUE. Duh.

Ouch, that brings back an old memory too. In my case I was using an
int, but casting to a byte (for bit-banging purposes) and failed to
see that my comparison was occurring while in byte form... leading to
exactly this problem. I thought I was safe by using an int, but
obviously incompetence can overcome any level of protection. (I mean
mine here, not yours!)

Paul

-- 
You received this message because you are subscribed to the Google Groups "The 
Java Posse" group.
To post to this group, send email to javapo...@googlegroups.com.
To unsubscribe from this group, send email to 
javaposse+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en.

Reply via email to