Binding to inline functions

Simon Marlow marlowsd at
Tue Aug 25 08:18:15 EDT 2009

On 23/08/2009 20:34, Duncan Coutts wrote:
> On Sun, 2009-08-23 at 15:09 -0300, Maurí­cio CA wrote:
>> I understand we can't use 'foreign import ccall'
>> to wrap inline C functions. Do you think it could
>> be possible to have an option in cabal to generate
>> such functions in an object file when #included in
>> a C file, in a compiler independent, portable way?
> It might be better to include this feature into hsc2hs and/or c2hs
> (which may in turn require some help from Cabal).

I think it would be easy to do in GHC.  We already have the machinery to 
generate the _stub.c files and compile them.

The main question is what the syntax should look like.  I was toying with

foreign import capi "foo" foo :: ...

where "capi" means the C API as opposed to the ABI, which is what ccall 
means.  This expresses the meaning without saying anything about the 
implementation - implementations that compile via C might not need a 
separate wrapper, so something like 'foreign import ccall "cwrapper 
foo"' would be wrong.

I wonder whether not being able to specify the actual calling convention 
will be a problem, however.  We are relying on the calling convention of 
foo being implicit.  Are there cases where this might cause a problem?


More information about the Libraries mailing list