[Haskell-cafe] FFI and struct arguments

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Thu Jul 17 07:46:02 EDT 2008

On Wed, 2008-07-16 at 22:45 -0300, Felipe Lessa wrote:
> Hi,
> I tried googling and searching the haskellwiki about this but wasn't
> lucky enough. My question is: is there a way to send struct arguments
> to C functions via the FFI or do I need to create a C wrapper? I guess
> there isn't, and while I can live without it, I'd like to leave no
> doubt.

Correct. The FFI spec does not support C structs as C function
parameters or results. You'll need a wrapper.

If the struct is passed by reference of course then you're fine, but if
it's by value then you need a C wrapper. The reason is because it's
beyond the scope of the FFI to know the structure layout and how to map
that to haskell types. That's the domain of FFI pre-processors. However
I don't know of any FFI pre-processors that help in this case. Passing C
structs by value seems to be pretty rare in exported C APIs.


More information about the Haskell-Cafe mailing list