[Haskell-cafe] FFI and struct arguments

Magnus Therning magnus at therning.org
Thu Jul 17 17:20:43 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.

You might find this old post of mine useful.

http://therning.org/magnus/archives/315

>
>
> 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!
>


-- 
Magnus Therning                             (OpenPGP: 0xAB4DFBA4)
magnus@therning.org             Jabber: magnus@therning.org
http://therning.org/magnus

Haskell is an even 'redder' pill than Lisp or Scheme.
     -- PaulPotts


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: OpenPGP digital signature
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20080717/1ab7bb3f/signature.bin


More information about the Haskell-Cafe mailing list