[Haskell-cafe] Re: question concerning ANSI "void *"

Ben Franksen ben.franksen at online.de
Fri Feb 8 16:23:20 EST 2008


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



More information about the Haskell-Cafe mailing list