Converting [Word8] to CString
Ashley Yakeley
ashley@semantic.org
Sat, 15 Sep 2001 21:39:19 -0700
At 2001-09-15 02:15, Marcin 'Qrczak' Kowalczyk wrote:
>Fri, 14 Sep 2001 23:40:42 -0700, Ashley Yakeley <ashley@semantic.org> pisze:
>
>> I'm looking for a function that will convert a [Word8] byte-array
>> to a CString (i.e. a C byte array) for the purposes of FFI.
>
>You can use newArray which allocates the C byte array using malloc
>so it must be freed by free, and cast the resulting pointer from
>Ptr Word8 to CString using castPtr.
Thank you. I ended up doing this and simply using Ptr Word8 as the FFI
type.
Curiously, the GHC user's guide sec. 8.2.4.1 seems to suggest that Ptr
types are illegal as arguments in foreign import function declarations. I
think this is the source of my confusion.
http://www.haskell.org/ghc/docs/latest/set/sec-primitive.html#SEC-PRIM-TYPE
S
--
Ashley Yakeley, Seattle WA