C99语法之栈上开辟内存
C/C++中在栈上开辟内存是最常见的,而且只要是在栈上开辟内存都要是固定的,而C99中有种用法相当奇葩
int *p = ((int[]){ [0] = 1, [15] = 10 });
在栈上分配这么一个空间,其反汇编结果如下:
1 int *p = ((int[]){ [0] = 1, [15] = 10 }); 2 00053F18 mov dword ptr [$S1],1 3 00053F1F mov dword ptr [ebp-50h],0 4 00053F26 mov dword ptr [ebp-4Ch],0 5 00053F2D mov dword ptr [ebp-48h],0 6 00053F34 mov dword ptr [ebp-44h],0 7 00053F3B mov dword ptr [ebp-40h],0 8 00053F42 mov dword ptr [ebp-3Ch],0 9 00053F49 mov dword ptr [ebp-38h],0 10 00053F50 mov dword ptr [ebp-34h],0 11 00053F57 mov dword ptr [ebp-30h],0 12 00053F5E mov dword ptr [ebp-2Ch],0 13 00053F65 mov dword ptr [ebp-28h],0 14 00053F6C mov dword ptr [ebp-24h],0 15 00053F73 mov dword ptr [ebp-20h],0 16 00053F7A mov dword ptr [ebp-1Ch],0 17 00053F81 mov dword ptr [ebp-18h],0Ah 18 00053F88 lea eax,[$S1] 19 00053F8B mov dword ptr [p],eax
这个也是在栈上开辟的因此需要指定,固定大小,也需要指定。
by:ECN14