[Haskell-cafe] FFI and struct arguments

kyra kyrab at mail.ru
Thu Jul 17 11:08:07 EDT 2008

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

Yes, but programmer *knows* the structure layout, so she usually can 
emulate it with a sequence of primary ffi type arguments. It's pretty 
trivial for the original example (see my previous post on this subj) and 
can be extended further. For example, in my homebrew COM library I 
pretty successfully marshall 16-byte Variants *by value* by means of two 
consecutive "legal" Word64 arguments.


More information about the Haskell-Cafe mailing list