This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Why "global" variable can't be processed properly ?
- From: Ian Lance Taylor <iant at google dot com>
- To: robinhorde at yahoo dot com dot cn
- Cc: gcc at gcc dot gnu dot org
- Date: Mon, 27 Apr 2009 22:13:15 -0700
- Subject: Re: Why "global" variable can't be processed properly ?
- References: <80994.25231.qm@web15706.mail.cnb.yahoo.com>
robinhorde@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-help@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