Re: C/C++ calling convention

Tech-Archive recommends: Speed Up your PC by fixing your registry



First, beaware that _cdecl is one of several calling conventions. As to your
questions:

1. There is a stack pointer per thread
2. The called function stores the stack pointer in another register, then
references the arguments as an offset of the register
3. There is no popping, so the stack has to be cleaned up.


--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
http://www.windrvr.com
Remove StopSpam from the email to reply


"Berger" <berger@xxxxxxxxxxx> wrote in message
news:uhp0Q6iiGHA.3496@xxxxxxxxxxxxxxxxxxxxxxx
A theoretical question: Sorry if its a beginner question.

Here is a quote from the MSDN explaning the C/C++ calling convention.. It
demonstrates that the calling function is responsible to clean the stack
pointer and it does it by the command "add esp,8" after returning from
the called function.

My questions:
1. Is the stack pointer common in a certain thread(or process)?
2. How does the called function get the parameters, is it by performing
twice pop functions?
3. If it pops twice why is there any need to clean the stack?
int _cdecl CFunc(int a, int b);

calling function called function
-------------------------------------------

push b _CFunc PROC NEAR
push a .
call _CFunc .
add esp,8 .
. RET
. _CFunc ENDP
.

int _cdecl CVarFunc(int a, ...);

Thanks for any refernce to my questions.

Berger





.



Relevant Pages

  • Re: C/C++ calling convention
    ... because the code to adjust the stack pointer afterwards isn't duplicated ... P.S. BTW in windows more popular than cdecl is stdcall ... int _cdecl CFunc; ...
    (microsoft.public.win32.programmer.kernel)
  • How implement pthread_measure_stack_usage on Linux
    ... function getcontext to get top stack pointer, ... int getStatckSize() ... I want the usage of memory, ...
    (comp.programming.threads)
  • Re: C/C++ calling convention
    ... the code to adjust the stack pointer afterwards isn't duplicated everywhere. ... P.S. BTW in windows more popular than cdecl is stdcall ... caller, cdecl used for functions with variable number of parameters, so ...
    (microsoft.public.win32.programmer.kernel)