-
Notifications
You must be signed in to change notification settings - Fork 52
Closed
Labels
Milestone
Description
While the Haskell FFI cannot create a foreign declaration to a variadic function that will accept an arbitrary number of arguments, it is possible to create a foreign declaration with a fixed number of arguments. For example, the C function int ioctl(int d, int request, ...)
can used in Haskell by forcing to have a specific type signature:
{-# LANGUAGE ForeignFunctionInterface #-}
module Main where
import Foreign
import Foreign.C.Types
foreign import ccall "ioctl" c_ioctl :: CInt -> CInt -> Ptr () -> IO CInt
However, one cannot do this with c2hs
, as it rejects all variadic functions. For example, this code:
{-# LANGUAGE ForeignFunctionInterface #-}
module Main where
import Foreign
import Foreign.C.Types
#include <sys/ioctl.h>
{#fun unsafe ioctl as c_ioctl
{ `Int'
, `Int'
, `Ptr ()'
} -> `Int' #}
will be rejected with the error:
./Main.chs:9: (column 3) [ERROR] >>> Variadic function!
Calling variadic functions is not supported by the FFI; the function
is defined at ("/usr/include/sys/ioctl.h": line 41).
Would there be any issues with relaxing c2hs
's restrictions on variadic functions to allow #fun
bindings?