
8 Feb
2008
8 Feb
'08
4:23 p.m.
Galchin Vasili wrote:
Let's take a concrete but "made up" case .. suppose we want to call through to pthread_create and pass the (void *) argument to pthread_create which in turn gets interpreted by the pthread that is launched. How would one populate the C struct that is passed to the launched pthread keeping in mind that this C struct is variable in length? From the FFI how would one model this C struct?
In this case I'd use Storable a => Ptr a and provide an instance Storable for the actual type you want to marshal. You can allocate the struct with Foreign.Marshal.Alloc.malloc and marshall it from Haskell to C with Foreign.Storable.poke. Cheers Ben