#include
int main()
{
int b = 3;
int arr[] = {6,7,8,9,10};
int *ptr = arr;
*(ptr++) += 123;
//printf("%d,%d\n", *ptr, *(++ptr)); //输出:8,8
printf("%d,%d\n", *ptr, *(ptr++));//输出:8,7
return 0;
}
_cdecl 压栈方式是从右到左
更加明显的例子:
#include
int main()
{
int a = 5, b = 7;
printf("%d %d\n",a,b);
return 0;
}
部分汇编代码:
printf("%d %d\n",a,b);
00251BBC mov esi,esp
00251BBE mov eax,dword ptr [b]
00251BC1 push eax
00251BC2 mov ecx,dword ptr [a]
00251BC5 push ecx
00251BC6 push 255858h
00251BCB call dword ptr ds:[2592BCh]
00251BD1 add esp,0Ch
00251BD4 cmp esi,esp
00251BD6 call __RTC_CheckEsp (025113Bh)
对于:
int a = 5;
printf("%d\n", (a = 2 * 5, a * 4), printf("%d\n", a));
可见使用VS 和使用 mingw32效果是不一样的!