here is the code:
DWORD SomeFunction(DWORD Dw_0, DWORD Dw_1, DWORD Dw_2)
{
return Dw_0 + Dw_1 + Dw_2;
}
void main()
{
DWORD Dw = 0;
DWORD pDw[3] = {1,2,3};
DWORD Dw_Sum = SomeFunction(pDw[Dw++], pDw[Dw++], pDw[Dw++]);
}
I expected VC++ 2008 generate code as SomeFunction(3,2,1) or
SomeFunction(1,2,3), however, the real code is like
SomeFunction(1,1,1)
I debug the and watch assembly code, find the code was generated with
push pDw[0] 3 times, then increase Dw by 3 times.
Can anyone tell me why?

Re: array variable subscript generate wrong code (2008) ? by Alex

Alex
Fri Apr 18 04:26:35 CDT 2008

"halison" wrote:
> here is the code:
> [...]
> DWORD Dw_Sum = SomeFunction(pDw[Dw++], pDw[Dw++], pDw[Dw++]);
> [...]
> I expected VC++ 2008 generate code as SomeFunction(3,2,1) or
> SomeFunction(1,2,3), however, the real code is like
> SomeFunction(1,1,1) I debug the and watch assembly code, find
> the code was generated with push pDw[0] 3 times, then increase
> Dw by 3 times. Can anyone tell me why?

"What's the value of i++ + i++?"
http://www.research.att.com/~bs/bs_faq2.html#evaluation-order

Alex