[Haskell-cafe] FFI and struct arguments

Felipe Lessa felipe.lessa at gmail.com
Wed Jul 16 21:45:19 EDT 2008


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.


Details:

I have something like

====================
typedef struct vect {
    float x,y;
} vect;

void func(vect v);
=====================

on the C side and

====================
-- Please disregard float /= Float, just an example :)
data Vector = Vector Float Float

instance Storable Vector where
    ...
====================

on the Haskell side, and I want to call func with Vector as argument.
Now, Vector isn't a basic FFI type, although it implements Storable.
So does that mean that I need to create something like

====================
void funcWrapper(vect *v) {
    func(*v);
}
====================

and then allocate some temporary memory on the Haskell side to use func?

Cheers!

-- 
Felipe.


More information about the Haskell-Cafe mailing list