[Haskell-Cafe] FFI and foreign function returning a structure

Ben Lippmeier Ben.Lippmeier at anu.edu.au
Tue Mar 1 22:45:54 EST 2005


Dimitry Golubovsky wrote:
> Hi,
> 
> If I have a C function returning a structure (not a pointer, but 
> structure itself), can this be accomodated via FFI?

No. The way data is organised in memory is dramatically different in 
Haskell when compared with C. You need to write functions to read in 
each field in turn and then "reconstruct" the structure on the Haskell 
side.

It's a tedious process. My advice is that if you have a lot of 
structures to read, write a (simple) preprocessor to generate the 
marshalling code.. that's what I did.

Ben.


More information about the Haskell-Cafe mailing list