Type promotion in ccall arguments
fjh at cs.mu.OZ.AU
Fri Mar 22 15:52:25 EST 2002
On 14-Mar-2002, Simon Marlow <simonmar at microsoft.com> wrote:
> I can't remember whether this has come up before, but to my surprise
> I've just discovered that FFI foreign import declarations don't contain
> enough infomration to be able to determine the correct calling
> convention for a given C function.
> Background: recently we "fixed" a bug in GHC's native code generator
> which was exposed by the following declaration:
> foreign import ccall unsafe
> snprintf :: CString -> CSize -> CString -> Float -> IO ()
I don't see how interfacing with a varargs function as if it had a
fixed prototype can ever be completely portable. C permits the calling
convention to be different for varargs functions, and sometimes this is
indeed desirable for efficiency: varargs functions require caller-pops
argument passing convention, but known-prototype functions can use a
more efficient callee-pops convention. Some C compilers have taken
advantage of this.
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
More information about the FFI