Stdcall v. ccall on Windows FFI
Hi, Haskell FFI addendum, when talking about calling conventions, says that[1]: ccall Calling convention of the standard C compiler on a system stdcall Calling convention of the Win32 API (matches Pascal conventions) I wonder: what would correspond to such "standard C compiler" in Windows? Is it, say, Visual Studio? And which convention does it use by default? Is it safe to assume that whatever is contained in a C file compiled inside a Cabal package in Windows will have a calling convention matched by 'ccall'? (The reason I'm asking this is because I maintain a FFI macro package[2] that is supposed to be portable between OSs, and I would like to be sure I give a good solution to Windows portability.) Thanks, Maurício [1] http://www.cse.unsw.edu.au/~chak/haskell/ffi/ffi/ffise3.html#x6-110003.1 [2] http://hackage.haskell.org/package/bindings-DSL
I'd say it depends entirely on the API that you are wrapping. Specifically the Win32 API on Windows uses stdcall, also OpenGL, but other more modern APIs use ccall. Visual studio can cope with either calling convention.
On 22/06/2011, at 1:28, Mauricio CA
Hi,
Haskell FFI addendum, when talking about calling conventions, says that[1]:
ccall Calling convention of the standard C compiler on a system stdcall Calling convention of the Win32 API (matches Pascal conventions)
I wonder: what would correspond to such "standard C compiler" in Windows? Is it, say, Visual Studio? And which convention does it use by default? Is it safe to assume that whatever is contained in a C file compiled inside a Cabal package in Windows will have a calling convention matched by 'ccall'?
(The reason I'm asking this is because I maintain a FFI macro package[2] that is supposed to be portable between OSs, and I would like to be sure I give a good solution to Windows portability.)
Thanks, Maurício
[1] http://www.cse.unsw.edu.au/~chak/haskell/ffi/ffi/ffise3.html#x6-110003.1 [2] http://hackage.haskell.org/package/bindings-DSL
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries
I'm not concerned with existing Windows libraries APIs (those can be stdcall or cdecl, I was told) , but with C code that you write yourself and that you build with your Haskell code. For instance: GHC will compile .c files given on its command line. Is it safe to assume that C functions compiled that way will have a calling convention matched by 'ccall'? Best, Maurício
I'd say it depends entirely on the API that you are wrapping. Specifically the Win32 API on Windows uses stdcall, also OpenGL, but other more modern APIs use ccall. Visual studio can cope with either calling convention.
Haskell FFI addendum, when talking about calling conventions, says that [...].
Is it safe to assume that whatever is contained in a C file compiled inside a Cabal package in Windows will have a calling convention matched by 'ccall'?
On 22 Jun, 2011,at 02:25 PM, Mauricio CA
On 22/06/2011 01:28, Mauricio CA wrote:
Hi,
Haskell FFI addendum, when talking about calling conventions, says that[1]:
ccall Calling convention of the standard C compiler on a system stdcall Calling convention of the Win32 API (matches Pascal conventions)
I wonder: what would correspond to such "standard C compiler" in Windows? Is it, say, Visual Studio? And which convention does it use by default? Is it safe to assume that whatever is contained in a C file compiled inside a Cabal package in Windows will have a calling convention matched by 'ccall'?
I'd say that ccall is the calling convention that a C compiler on that platform will use unless you specify otherwise. For example, on Windows you always have to specify __stdcall if you want it - the Win32 header files have it all over the place, and you can't call Win32 functions by defining their prototypes yourself unless you add __stdcall. So the answer to your last question is "yes" Cheers, Simon
participants (4)
-
Malcolm Wallace -
malcolm.wallace -
Mauricio CA -
Simon Marlow