Re: cdecl support
- Posted by Robert Craig <rds at RapidEuphoria.com> Feb 26, 2002
- 416 views
Karl Bochert writes: > Is it really that simple, or am I overlooking something? For most Euphoria programs, preserving the stack pointer as you describe, will probably solve the problem, but there's a bit more to it than that. According to the notes I made a year ago, structures, and floating point values (C doubles), are also passed and returned differently. Structures don't matter to us, but doubles occasionally do. Here are the notes I have. I found that this stuff is very poorly documented. Calling Convention Info ======================= Common to BOTH __cdecl AND __stdcall: 1. Arguments are pushed on the stack from right to left. That is, the last argument is pushed first. 2. Registers EAX, ECX and EDX are not saved and restored when a call is made. __cdecl: - The calling routine will remove the arguments from the stack. - Floating-point values are returned in the same way as structures. When a structure is returned, the called routine allocates space for the return value and returns a pointer to the return value in register EAX. __stdcall: - All C symbols (extern "C" symbols in C++) are suffixed by "@nnn" where "nnn" is the sum of the argument sizes (each size is rounded up to a multiple of 4 bytes so that char and short are size 4). When the argument list contains "...", the "@nnn" suffix is omitted. - The called routine will remove the arguments from the stack. - When a structure is returned, the caller allocates space on the stack. The address of the allocated space will be pushed on the stack immediately before the call instruction. Upon returning from the call, register EAX will contain address of the space allocated for the return value. Floating-point values are returned in 80x87 register ST(0). Regards, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com