[Haskell-cafe] FFI and struct arguments

kyra kyrab at mail.ru
Thu Jul 17 02:57:03 EDT 2008

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.
Sometimes there is such a way. See below.
> Details:
> I have something like
> ====================
> typedef struct vect {
>     float x,y;
> } vect;
> void func(vect v);
For most architectures stack layout of

void func(vect v);


void func(float x, float y);

is exactly the same, so for FFI purposes this 'func' can be declared as 
something like:

foreign import ccall unsafe :: Float -> Float -> IO ()


More information about the Haskell-Cafe mailing list