This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Qwery regarding the While() in gcc (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
- From: Falk Hueffner <falk dot hueffner at student dot uni-tuebingen dot de>
- To: Riyash M H <riyash_mon at yahoo dot co dot in>
- Cc: gcc-help at gcc dot gnu dot org
- Date: 25 Feb 2004 09:15:02 +0100
- Subject: Re: Qwery regarding the While() in gcc (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
- References: <20040225071231.18906.qmail@web8307.mail.in.yahoo.com>
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