This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]