This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]