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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Riyash M H <riyash_mon@xxxxxxxxxxx> 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

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux