Advertisement

stdcall, cdecl. ?

Started by December 06, 2001 05:18 PM
7 comments, last by Askadar 22 years, 11 months ago
Hi, I never bothered very much about how my compiler did the calling, but now I''m using more libs and I started to wonder where the differences are. Where are the advantages? Where are the drawbacks? Is fastcall actually faster? Thx folks for helping me!
Kill mages first!
__cdecl: c style function call, allows for variable number of arguments to be passed to a function. calling function cleans up the stack.

__stdcall: pascal style function, does not allow for variable number of arguments because the stack is cleaned up by the calling function. usually faster than "__cdecl".

__fastcall: tries to pass parameters in registers instead of using the stack. no stack to cleanup.

__thiscall: the implicit "this" reference is passed in the "ecx" register on Intel machines of course. probably the "a0" register on MIPS processors.

WINAPI functions use "__stdcall".

To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
Advertisement
no, no, my bad.

__stdcall: stack is cleaned up by the called function.

geez.

To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
Thank you!

So for time critical functions, in games for example, __fastcall would be desirable? Or is the difference not noticeable?
Kill mages first!
It''s not noticeable, but if you really have some sort of hard core graphics crunching intensive function, code it in ASM x86.
This may be a ''no duh'' to many of you...but to ''fill in the blanks'' for the newbies...

when a program makes a standard function call...it first PUSHes the current memory location onto the stack...then it pushes the argumanes onto the stack...it then transfers the execution pointer to where the function resides in memory...goes there...then POPs the argument values back off the stack...does whatever....then pops the previous memory location off the stack...pushes the return value onto the stack...and transfers back to the originateing memory location...where the return value gets poped back off the stack to be used...

hope I didn''t mess that up to bad...it''s been a while sense I wrote anything in assembler
Advertisement
MSW: your statement about return values is incorrect.

under the Intel architecture, return values of 32-bit''s or less are passed in register "eax". 64-bit values are passed in the register pair "eax/edx". structures are passed as a pointer to a reserved space of the structure size. other architectures use the same convention (i.e. MIPS reserves registers "v0/v1" for return values).

peace.

To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
ACK!...sorry!...my bad

Mmm...actually that could explain a few problems I had with some sprite routines years ago
MSW: no worries, it''s compiler specific anyway. this is just common & recommended way to return values.

To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.

This topic is closed to new replies.

Advertisement