Quoting from here,
For many compilers, the standard function entry sequence is the following piece of code (X is the total size, in bytes, of all automatic variables used in the function):
push ebp mov ebp, esp sub esp, X
I am in Visual Studio 2015, 64 bit Intel Processor machine. I am examining a very simple main function via disassembly where even though I only have two auto variables, esp ends up allocating a lot more (216 bytes) than the space for two variables. Relevant code appears below.
int main() {
00E61650 push ebp
00E61651 mov ebp,esp
00E61653 sub esp,0D8h ; why is esp being decremented by 0D8h
;which is decimal for 216 even though there
;are only two auto variables, a and b?
00E61659 push ebx
00E6165A push esi
00E6165B push edi
00E6165C lea edi,[ebp-0D8h]
00E61662 mov ecx,36h
00E61667 mov eax,0CCCCCCCCh
00E6166C rep stos dword ptr es:[edi]
int a = 5;
00E6166E mov dword ptr [a],5
int b = a + 6;
00E61675 mov eax,dword ptr [a]
00E61678 add eax,6
00E6167B mov dword ptr [b],eax
return 0;
00E6167E xor eax,eax
}
Do auto variables in main() require more memory than auto variables in other functions?