Mail Archives: djgpp/1997/06/28/10:37:39
> Ok, I know chars are byte values, but
> they seemed to be signed in DJGPP
I think they are signed in most compilers. GCC gives an option to
make them unsigned as you mention.
> But, w/the unsigned char flag on, I get an infinite
> loop
Um, you should get an infinite loop with it off also.
> If anybody has a work around (while loop, a mix of C wrapped
> in an inline ASM loop) or any other help would be great;
^^^^^^^^^^
Nothing so drastic.
> Here's a vague description of my code:
>
> void stupid_error(char get_some_stupid_vars)
> {
>
> char c;
>
> for(c=0;c<=255;c++)
> {
> /* do some stupid newbie stuff */
> }
>
> }
>
OK - lets assume that the char datatype is an unsigned 8 bit value.
That means the largest number it can store is 255. Look what happens
in your code as the variable hits 255. Test for <=, yep 255<=255. Now,
increment. Here it will roll to 0. Now test for <=, yep 0 <= 255.
Instant infinite loop.
Possible solutions -
Use an int data type.
Change the conditions of your loop
Andrew
- Raw text -