Qwery regarding the While() in gcc (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)

Falk Hueffner falk.hueffner@student.uni-tuebingen.de
Wed Feb 25 10:00:00 GMT 2004


Riyash M H <riyash_mon@yahoo.co.in> writes:

> I am using gcc (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5). I have
> got a code which is not working according to what i expect. Can u
> tell me the reason behind that or is that a bug in the gcc version,
> i dont have another complier, i executed it with its "g++ " clone
> also. That too gave me the same results,
> 
> -----------------------------------------
> 
> int main(){
>         unsigned short i = 3;
>         while(i > -1)
>                 printf("%u\n",i--);
>         return 0;
> }
> 
> output: 3,2,1,0,65535,...............
> ------------------------------------------- 

The reason is that "i" is promoted to "int" before the comparison, as
the C standard mandates.

-- 
	Falk



More information about the Gcc-help mailing list