This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Why "global" variable can't be processed properly?
- From: me22 <me22 dot ca at gmail dot com>
- To: robinhorde at yahoo dot com dot cn
- Cc: gcc-help at gcc dot gnu dot org
- Date: Tue, 28 Apr 2009 10:24:08 -0400
- Subject: Re: Why "global" variable can't be processed properly?
- References: <929898.93313.qm@web15708.mail.cnb.yahoo.com>
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