avr-gcc-list
[Top][All Lists]
Advanced

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

Re: [avr-gcc-list] OT Generic C question


From: Colin Paul Gloster
Subject: Re: [avr-gcc-list] OT Generic C question
Date: Tue, 20 Sep 2005 13:20:56 +0100

Please pose C questions to a relevant medium, e.g. the programming questions
list of the ACCU ( WWW.ACCU.org ) or one of the C newsgroups ( e.g. 
news:comp.lang.c
or the C learners' newsgroup).


On Tue, 20 Sep 2005 13:47:49 +0200, David Brown emailed:


"I'd agree with you that i should be 1 after "i = i++", despite the sillyness
of the statement. [..] it's quite likely that it remained at 0
due to legitimate compiler optomisations."


I am not convinced that i should be 1 after i = i++ and I am not convinced
that optimization is relevant.


On Tue, 20 Sep 2005 13:35:13 +0200 Bernard Fouché emailed:


"Trampas wrote:

 >I was helping a friend debug some code, he is new to C,  using the Keil
 >version of GCC for ARM. Anyway I found the following:
 >
 >int i;
 >
 >i=0;
 >i=i++;
 >//i was still zero that
 >
 >That is i=i++ never incremented i, now I would have thought the line would
 >be the same as:
 >
 >i=i;
 >i=i+1;
 >
 >
 >
 >
 i++ means 'get i value, afterwards increment it'. So

 i=i++ will increment i, but after having read it to assign its value to

 itself :-)

[..]"

I think that the rules of the value of the expression i++ might be different
in C and Java, but in both languages, i=i++; means to assign the value of
the expression i++ to i and in at least one of those languages, the value
of the expression i++ is not equivalent to the sideeffect which i++ has on
i. Please check for yourself what it is defined to be in C.






reply via email to

[Prev in Thread] Current Thread [Next in Thread]