27: const int NUM = 1;28: void main()29: {0040B7A0 push ebp0040B7A1 mov ebp,esp0040B7A3 sub esp,48h0040B7A6 push ebx0040B7A7 push esi0040B7A8 push edi0040B7A9 lea edi,[ebp-48h]0040B7AC mov ecx,12h0040B7B1 mov eax,0CCCCCCCCh0040B7B6 rep stos dword ptr [edi]30: int a = NUM;0040B7B8 mov dword ptr [ebp-4],131: int *p = (int *)&NUM;0040B7BF mov dword ptr [ebp-8],offset NUM (0042001c)32: (*p)++;0040B7C6 mov eax,dword ptr [ebp-8]0040B7C9 mov ecx,dword ptr [eax]0040B7CB add ecx,10040B7CE mov edx,dword ptr [ebp-8]0040B7D1 mov dword ptr [edx],ecx33:34: }以上是本人在Vc6.0环境上编译的代码,通过反汇编可以看到,const常量NUM是占用内存的,但是地址并不是在栈内,而且使用常量的地方其实都直接使用的立即数,另外(*P)++的地方会死掉,请教高手给与解答一二。因为我刚注册,所以没有积分,请大侠不要介意补充:我的朋友在linux下也做同样的事情确能编译过,而且运行也有结果const int num = 3;cout << &num << endl;int * p = (int*)#(*p)++;cout << (*p) << endl;cout << num << endl;结果0x7fbffff7ac43这又怎么理解?
添加回答
举报
0/150
提交
取消