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: Bernard Fouché
Subject: Re: [avr-gcc-list] OT Generic C question
Date: Tue, 20 Sep 2005 13:35:13 +0200
User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)

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 :-)

The place where "++" is located is important. You may have wanted:

i=++i;   (this time 'i' is incremented before 'i' value is read)

but if the whole point is just to have 'i' incremented by one then

i++;              is enough

or

i+=1;


 Bernard




reply via email to

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