Hi Trampas,

Thats why you have an post-increment operator and pre-increment operator.

i=++i;

will give you the result, you'd expected.

i++, will execute the assignment and after that the value gets inc'd
++i, will inc'd and then assign

Hopefully I got it right :)

/Marc


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;
So you guys are the smartest people I know when it comes to C so I thought I
would ask you guys if this is a compiler bug or is my understanding of C
just been shaken.
Regards,
Trampas




_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list



_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Reply via email to