Call Conventions

Dan murpsoft at hotmail.com
Fri Jan 4 01:23:28 PST 2008


Alan Knowles Wrote:

> While it's not going to solve that issue, I think this should achieve 
> what you are trying to do, although not quite as clean...

Unfortunately, no, that's quite a ways off the mark from what I'm trying to do.

I was hoping to change how the program internally handles function calls.  For example;

if we use "extern(C)", 
- all the arguments are pushed onto the stack from right to left
- return value is in eax or fp0
- cleanup is by the caller.

So when we go:

extern(C) int main(char[][] arguments),

the caller knows to get the result from eax, and to push twice to make a D array, and to add 4 to esp afterwards to clean up.

the callee knows that if there are any local variables, it needs to wiggle ebp and esp to cause the local variables to get wiped when the function returns.

That's _cdecl.  There's also syscall, optlink, pascal, fastcall, stdcall, safecall, and thiscall amongst the ones listed on wikipedia:

http://en.wikipedia.org/wiki/X86_calling_conventions

I was hoping to roll my own which allowed me to pass Value structs by SSE2 registers.  Perhaps that's a little optimistic, but that's what got me thinking about this.



More information about the Digitalmars-d mailing list