robinho...@yahoo.com.cn writes:

>   I have a question about "global" variable accessing when gcc compile
>   some code. See example below:

This question would be more appropriate for the mailing list
gcc-h...@gcc.gnu.org.  Please take any follow-ups to that list.


> int GetNewValue( int iValue )
> {
>     //do something...
>
>     //i change the global variable intentionally.
>     iCurArrayIdx = 1;   
>
>     //assume the return is 1
>     return 1;
> }
>
> int main(int argc, char* argv[])
> {
>     aiArray[iCurArrayIdx] = GetNewValue( aiArray[iCurArrayIdx] );
>
>     printf( "aiArray[iCurArrayIdx] = %d\n", aiArray[iCurArrayIdx] );
>
>     return 0;
> }

The order of evaluation of the left hand side and the right hand side of
the assigment operator is unspecified in C.  Therefore, the behaviour of
this program is unspecified, because iCurArrayIdx could be retrieved
before or after GetNewValue is called, and different compilers are free
to implement this program differently.

Ian

Reply via email to