为什么我们为每个变量分配12个字节? [英] Why do we allocate 12 bytes for each variable?

查看:88
本文介绍了为什么我们为每个变量分配12个字节?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Visual Studio 2010专业版(x86,Windows 7)中:

In visual Studio 2010 Professional (x86, Windows 7):

... more
00DC1362 B9 39 00 00 00       mov         ecx,39h  
00DC1367 B8 CC CC CC CC       mov         eax,0CCCCCCCCh  
00DC136C F3 AB                rep stos    dword ptr es:[edi]  
    20:     int a = 3;
00DC136E C7 45 F8 03 00 00 00 mov         dword ptr [ebp-8],3  
    21:     int b = 10;
00DC1375 C7 45 EC 0A 00 00 00 mov         dword ptr [ebp-14h],0Ah  
    22:     int c;
    23:     c = a + b;
00DC137C 8B 45 F8             mov         eax,dword ptr [ebp-8]  
00DC137F 03 45 EC             add         eax,dword ptr [ebp-14h]  
00DC1382 89 45 E0             mov         dword ptr [ebp-20h],eax  
    24:     return 0;

请注意,相对寻址变量A和B如何不按字长4对齐? 这是怎么回事

Notice how the relative addressing variable A and B are not aligned by word size of 4? What is happening here?

此外,为什么我们跳过$ ebp-8?

关闭优化将显示理想的寻址方案.

Turning off the optimization will show the ideal addressing scheme.

有人可以解释原因吗?谢谢.

Can someone please explain the reason? Thanks.

每个变量的偏移量是12个字节. A-> B-> C 我犯了一个错误.我的意思是为什么我们跳过前8个字节.

The offset of each variable is 12 bytes. A -> B -> C I made a mistake. I meant why do we skip the first 8 bytes.

推荐答案

您正在查看由默认Debug构建设置生成的代码.特别是/RTC选项(启用运行时错误检查).用0xcccccccccc填充有助于诊断未初始化的变量,间隙有助于诊断溢出.

You are looking at the code generated by the default Debug build setting. Particularly the /RTC option (enable run-time error checks). The filling with 0xcccccccc helps diagnose uninitialized variables, the gaps help diagnose overflow.

看这段代码没有多大意义,您不会将其发布.再说一次,在Release版本中将没有任何此功能.

There isn't much point in looking at this code, you are not going to ship that. Then again, there won't be anything left of this function in the Release build.

这篇关于为什么我们为每个变量分配12个字节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆