C语言复杂声明解析
https://blog.csdn.net/wangweixaut061/article/details/6549768
文章有点长,耐心看完,会对你有帮助的
下面两个程序是一样的,至少在汇编语言层是一样的
#include <stdio.h>
#include <stdlib.h>
#define STACK_INIT_SIZE 100
typedef double ElemType;
typedef struct
{
ElemType *base;
ElemType *top;
} sqStack;
void InitStack(sqStack *s)
{
00FBF0E0 55 push ebp
00FBF0E1 8B EC mov ebp,esp
00FBF0E3 81 EC C0 00 00 00 sub esp,0C0h
00FBF0E9 53 push ebx
00FBF0EA 56 push esi
00FBF0EB 57 push edi
00FBF0EC 8D BD 40 FF FF FF lea edi,[ebp-0C0h]
00FBF0F2 B9 30 00 00 00 mov ecx,30h
00FBF0F7 B8 CC CC CC CC mov eax,0CCCCCCCCh
00FBF0FC F3 AB rep stos dword ptr es:[edi]
s->base = malloc(STACK_INIT_SIZE * sizeof(ElemType));
00FBF0FE 68 20 03 00 00 push 320h
00FBF103 E8 12 AD FF FF call _malloc (0FB9E1Ah)
00FBF108 83 C4 04 add esp,4
00FBF10B 8B 4D 08 mov ecx,dword ptr [s]
00FBF10E 89 01 mov dword ptr [ecx],eax
s->top = s->base;
00FBF110 8B 45 08 mov eax,dword ptr [s]
00FBF113 8B 4D 08 mov ecx,dword ptr [s]
00FBF116 8B 11 mov edx,dword ptr [ecx]
00FBF118 89 50 04 mov dword ptr [eax+4],edx
}
00FBF11B 5F pop edi
00FBF11C 5E pop esi
00FBF11D 5B pop ebx
00FBF11E 81 C4 C0 00 00 00 add esp,0C0h
00FBF124 3B EC cmp ebp,esp
00FBF126 E8 58 B2 FF FF call __RTC_CheckEsp (0FBA383h)
00FBF12B 8B E5 mov esp,ebp
00FBF12D 5D pop ebp
00FBF12E C3 ret
--- 无源文件 -----------------------------------------------------------------------
00FBF12F CC int 3
00FBF130 CC int 3
00FBF131 CC int 3
00FBF132 CC int 3
00FBF133 CC int 3
00FBF134 CC int 3
00FBF135 CC int 3
00FBF136 CC int 3
00FBF137 CC int 3
00FBF138 CC int 3
00FBF139 CC int 3
00FBF13A CC int 3
00FBF13B CC int 3
00FBF13C CC int 3
00FBF13D CC int 3
00FBF13E CC int 3
00FBF13F CC int 3
00FBF140 CC int 3
00FBF141 CC int 3
00FBF142 CC int 3
00FBF143 CC int 3
00FBF144 CC int 3
00FBF145 CC int 3
00FBF146 CC int 3
00FBF147 CC int 3
00FBF148 CC int 3
00FBF149 CC int 3
00FBF14A CC int 3
00FBF14B CC int 3
00FBF14C CC int 3
00FBF14D CC int 3
00FBF14E CC int 3
00FBF14F CC int 3
--- c:\visualstudioprojects\c\c\main.c -----------------------------------------
int main(void)
{
00FBF150 55 push ebp
00FBF151 8B EC mov ebp,esp
00FBF153 81 EC D0 00 00 00 sub esp,0D0h
00FBF159 53 push ebx
00FBF15A 56 push esi
00FBF15B 57 push edi
00FBF15C 8D BD 30 FF FF FF lea edi,[ebp-0D0h]
00FBF162 B9 34 00 00 00 mov ecx,34h
00FBF167 B8 CC CC CC CC mov eax,0CCCCCCCCh
00FBF16C F3 AB rep stos dword ptr es:[edi]
sqStack s;
InitStack(&s);
00FBF16E 8D 45 F4 lea eax,[s]
00FBF171 50 push eax
00FBF172 E8 78 C8 FF FF call _InitStack (0FBB9EFh)
00FBF177 83 C4 04 add esp,4
return 0;
00FBF17A 33 C0 xor eax,eax
}
00FBF17C 52 push edx
00FBF17D 8B CD mov ecx,ebp
00FBF17F 50 push eax
00FBF180 8D 15 A4 F1 FB 00 lea edx,ds:[0FBF1A4h]
00FBF186 E8 B6 C1 FF FF call @_RTC_CheckStackVars@8 (0FBB341h)
00FBF18B 58 pop eax
00FBF18C 5A pop edx
00FBF18D 5F pop edi
00FBF18E 5E pop esi
00FBF18F 5B pop ebx
00FBF190 81 C4 D0 00 00 00 add esp,0D0h
00FBF196 3B EC cmp ebp,esp
00FBF198 E8 E6 B1 FF FF call __RTC_CheckEsp (0FBA383h)
00FBF19D 8B E5 mov esp,ebp
00FBF19F 5D pop ebp
00FBF1A0 C3 ret
//#include <stdio.h>
//#include <stdlib.h>
//
//#define STACK_INIT_SIZE 100
//
//typedef double ElemType;
//
//typedef struct
//{
// ElemType *base;
// ElemType *top;
//} sqStack;
//
//void InitStack(sqStack *s)
//{
// s->base = malloc(STACK_INIT_SIZE * sizeof(ElemType));
// s->top = s->base;
//}
//
//int main(void)
//{
// sqStack s;
// InitStack(&s);
//
// return 0;
//}
#include <stdio.h>
#include <stdlib.h>
#define STACK_INIT_SIZE 100
//typedef double ElemType;
typedef struct
{
double *base;
double *top;
} sqStack;
void InitStack(sqStack *s)
{
0007F0E0 55 push ebp
0007F0E1 8B EC mov ebp,esp
0007F0E3 81 EC C0 00 00 00 sub esp,0C0h
0007F0E9 53 push ebx
0007F0EA 56 push esi
0007F0EB 57 push edi
0007F0EC 8D BD 40 FF FF FF lea edi,[ebp-0C0h]
0007F0F2 B9 30 00 00 00 mov ecx,30h
0007F0F7 B8 CC CC CC CC mov eax,0CCCCCCCCh
0007F0FC F3 AB rep stos dword ptr es:[edi]
s->base = malloc(STACK_INIT_SIZE * sizeof(double));
0007F0FE 68 20 03 00 00 push 320h
0007F103 E8 12 AD FF FF call _malloc (079E1Ah)
0007F108 83 C4 04 add esp,4
0007F10B 8B 4D 08 mov ecx,dword ptr [s]
0007F10E 89 01 mov dword ptr [ecx],eax
s->top = s->base;
0007F110 8B 45 08 mov eax,dword ptr [s]
0007F113 8B 4D 08 mov ecx,dword ptr [s]
0007F116 8B 11 mov edx,dword ptr [ecx]
0007F118 89 50 04 mov dword ptr [eax+4],edx
}
0007F11B 5F pop edi
}
0007F11C 5E pop esi
0007F11D 5B pop ebx
0007F11E 81 C4 C0 00 00 00 add esp,0C0h
0007F124 3B EC cmp ebp,esp
0007F126 E8 58 B2 FF FF call __RTC_CheckEsp (07A383h)
0007F12B 8B E5 mov esp,ebp
0007F12D 5D pop ebp
0007F12E C3 ret
--- 无源文件 -----------------------------------------------------------------------
0007F12F CC int 3
0007F130 CC int 3
0007F131 CC int 3
0007F132 CC int 3
0007F133 CC int 3
0007F134 CC int 3
0007F135 CC int 3
0007F136 CC int 3
0007F137 CC int 3
0007F138 CC int 3
0007F139 CC int 3
0007F13A CC int 3
0007F13B CC int 3
0007F13C CC int 3
0007F13D CC int 3
0007F13E CC int 3
0007F13F CC int 3
0007F140 CC int 3
0007F141 CC int 3
0007F142 CC int 3
0007F143 CC int 3
0007F144 CC int 3
0007F145 CC int 3
0007F146 CC int 3
0007F147 CC int 3
0007F148 CC int 3
0007F149 CC int 3
0007F14A CC int 3
0007F14B CC int 3
0007F14C CC int 3
0007F14D CC int 3
0007F14E CC int 3
0007F14F CC int 3
--- c:\visualstudioprojects\c\c\main.c -----------------------------------------
int main(void)
{
0007F150 55 push ebp
0007F151 8B EC mov ebp,esp
0007F153 81 EC D0 00 00 00 sub esp,0D0h
0007F159 53 push ebx
0007F15A 56 push esi
0007F15B 57 push edi
0007F15C 8D BD 30 FF FF FF lea edi,[ebp-0D0h]
0007F162 B9 34 00 00 00 mov ecx,34h
0007F167 B8 CC CC CC CC mov eax,0CCCCCCCCh
0007F16C F3 AB rep stos dword ptr es:[edi]
sqStack s;
InitStack(&s);
0007F16E 8D 45 F4 lea eax,[s]
0007F171 50 push eax
0007F172 E8 78 C8 FF FF call _InitStack (07B9EFh)
0007F177 83 C4 04 add esp,4
return 0;
0007F17A 33 C0 xor eax,eax
}
0007F17C 52 push edx
0007F17D 8B CD mov ecx,ebp
0007F17F 50 push eax
}
0007F180 8D 15 A4 F1 07 00 lea edx,ds:[7F1A4h]
0007F186 E8 B6 C1 FF FF call @_RTC_CheckStackVars@8 (07B341h)
0007F18B 58 pop eax
0007F18C 5A pop edx
0007F18D 5F pop edi
0007F18E 5E pop esi
0007F18F 5B pop ebx
0007F190 81 C4 D0 00 00 00 add esp,0D0h
0007F196 3B EC cmp ebp,esp
0007F198 E8 E6 B1 FF FF call __RTC_CheckEsp (07A383h)
0007F19D 8B E5 mov esp,ebp
0007F19F 5D pop ebp
0007F1A0 C3 ret
//#include <stdio.h>
//#include <stdlib.h>
//
//#define STACK_INIT_SIZE 100
//
//typedef double ElemType;
//
//typedef struct
//{
// ElemType *base;
// ElemType *top;
//} sqStack;
//
//void InitStack(sqStack *s)
//{
// s->base = malloc(STACK_INIT_SIZE * sizeof(ElemType));
// s->top = s->base;
//}
//
//int main(void)
//{
// sqStack s;
// InitStack(&s);
//
// return 0;
//}
#include <stdio.h>
#include <stdlib.h>
#define STACK_INIT_SIZE 100
//typedef double ElemType;
typedef struct
{
double *base;
double *top;
} sqStack;
void InitStack(sqStack *s)
{
s->base = malloc(STACK_INIT_SIZE * sizeof(double));
s->top = s->base;
}
int main(void)
{
sqStack s;
InitStack(&s);
return 0;
}
|