Re: Request for help

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

 



> 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.


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux