Request for help

Andrew Bevitt andrew@volutin.net
Wed Jan 7 04:44:00 GMT 2004


> a[i]=a[i++]; 

I read this as saying assign to the array a's position i, the value stored
in array a's position i, and then increment i. In code this would be 

a[i] = a[i]; i++; 

> Looks like gcc is treating this as a[i]=a[i];i++; Where as the
> programmers intention could be a[i+1]=a[i];i++;

The programmers intention could never be that unless they really 
are not sure about prefix / postfix notation and the usage of arrays.

There are subtle differences: A) Assign to array a's position i, the
value stored in array a at position i, then increment i. B) Assign to
array a's position i+1 the value of array a at position i, then inc i.

> Does the C language ANSI standard enforce any evaluation order or the
> implementation is left to the compiler?

i++ will increase i after any other operation on the line is complete
++i will increase i and then perform the other operations.

Note you cannot just issue : a[i] = a[++i]; either though, as the new position
i (ie i+1) will be used for both the assigned value position and the read.



More information about the Gcc-help mailing list