[Haskell-beginners] How to initialize a C struct with FFI
Marco De Oliveira
deolivem at gmail.com
Sat Feb 6 06:28:31 EST 2010
Hi,
I try to initialize a C struct using the FFI API and ghc stays blocked when
I execute my code (and I got sometimes the error "out of memory").
I do not understand, I do not find any mistake in my code:
{-# OPTIONS -XTypeSynonymInstances #-}
import Foreign.C.Types
import Foreign.Marshal.Alloc
import Foreign.Ptr
import Foreign.Storable
type CStruct = (CULong, CULong)
instance Storable CStruct where
sizeOf _ = 2*sizeOf (undefined::CULong)
alignment _ = alignment (undefined::CULong)
test = alloca (\pStruct -> do
poke pStruct ( (fromIntegral 1)::CULong, (fromIntegral 1)::CULong )
)
Thanks for your help.
Marco
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20100206/b94d5a8d/attachment.html
More information about the Beginners
mailing list