Re: Pascal calling convention
- Posted by jacques deschĂȘnes <desja at globetrotter.net> May 07, 2005
- 463 views
Hayden McKay wrote: > > While playing arround with some Delphi DLL's I noticed that Euphoria supports > the "pascal" calling convention as well. I thought some people might want to > know how to support the "pascal" calling methed in Euphoria so I've included > some info for those who are interrested. > > Euphoria's standard c_proc()/c_func() method pushes the values onto the stack > from "right to left". The only defference with the pascal convention is that > the values are pushed onto the stack from "left to right". > > The example demonstrates the SAME C routine using the stdcel and pascal call > The file "test.dll" contains the same procedure declared twice. one with the > "stdcel" method and the other declared as "pascal" method. > There is more to calling convention than the push order here more information about it extracted from the folowing page: <a href="http://info.borland.com/techpubs/delphi/delphi5/oplg/procfunc.html#8406">calling convention</a> Calling conventions determine the order in which parameters are passed to the routine. They also affect the removal of parameters from the stack, the use of registers for passing parameters, and error and exception handling. The default calling convention is register. * The register and pascal conventions pass parameters from left to right; that is, the leftmost parameter is evaluated and passed first and the rightmost parameter is evaluated and passed last. The cdecl, stdcall, and safecall conventions pass parameters from right to left. * For all conventions except cdecl, the procedure or function removes parameters from the stack upon returning. With the cdecl convention, the caller removes parameters from the stack when the call returns. * The register convention uses up to three CPU registers to pass parameters, while the other conventions pass all parameters on the stack. * The safecall convention implements COM error and exception handling. regards, Jacques D.