Why "global" variable can't be processed properly?

me22 me22.ca@gmail.com
Tue Apr 28 14:24:00 GMT 2009


2009/4/28 Robin.Horde <robinhorde@yahoo.com.cn>:
>
>  I have a question about "global" variable accessing when gcc compile some code. See example below:
>
>    aiArray[iCurArrayIdx] = GetNewValue( aiArray[iCurArrayIdx] );
>

I'm not sure, but it feels like this is due to unspecified order of
evaluation.  There's nothing that says that GetNewValue needs to be
evaluated before the aiArray + iCurArrayIdx in the LHS, so it's
probably the old use-and-modification between sequence points problem.

To put it another way, one compiler is doing this:

 int t = GetNewValue( aiArray[iCurArrayIdx] );
 aiArray[iCurArrayIdx] = t;

while the other is doing this:

 int &t = aiArray[iCurArrayIdx];
 t = GetNewValue( aiArray[iCurArrayIdx] );

and I don't know of anything that specifies that it's supposed to be
one or the other.

~ Scott



More information about the Gcc-help mailing list