RE: stdcall
"Simon Marlow" <[email protected]>
| Newsgroups | gmane.comp.lang.haskell.ffi |
|---|---|
| Message-ID | <3429668D0E777A499EE74A7952C382D18BB67F@EUR-MSG-01.europe.corp.microsoft.com> |
> On Saturday 19 July 2003 12:51 am, Ross Paterson wrote: > > Could the meaning of stdcall be broadened to "the standard calling > > convention for libraries on the native system", i.e. pascal on Win32 > > (as now) and ccall on Unix? It would save a lot of fuss > for interfaces > > to portable libraries. > > If I understand you correctly: > > 1) Even on Win32, a function defined with type: > > rty foo(argtys) > > should be called using stdcall. I don't think that's true. The default calling convention on Windows is still ccall (known as __cdecl to the C compiler), it's just that cross-DLL calls are normally done using the __stdcall calling convention. On Windows, functions in the C runtime are called using the __cdecl calling convention. I just tested this by checking the assembly generated for calling malloc(). Although __stdcall is used more often than __cdecl for library calls on Windows, it doesn't seem to be used exclusively (someone correct me if I'm wrong). So I'd say that specifying a "default" calling convention which maps to stdcall on Windows and ccall on Unix is probably a bad idea. You've just got to know which one to use on Windows - this is the job for a tool which checks the FFI decls against the prototypes. Cheers, Simon