I’m having a weird problem with avr-gcc. If I do this:
int i = 0;
i = ++i;
It results in the compiler warning:
warning: operation on ‘i’ may be undefined
What is wrong here?
If it is rewritten to
i = i + 1;
It does not result in the warning.
avr-gcc is version 4.3.4 and I’m running this on Ubuntu 10.04.
If you intended to simply increment
i, then use eitheror
(or
i++), but not both. The rules of C don’t permit you to modify a variable twice before a single sequence point. Both the preincrement (++i) and the assignment (i =) modify the value ofi.