Possible Duplicate:
Can the FFI deal with arrays? If so, how?
I have a tiny assembler written in Haskell which takes a string with assembly code and returns a string of binary machine code. I want to be able to use this function in C by building this Haskell library as a shared library. The binary machine code can contain null values so I can't use CString
as return type, since that is a regular null-terminated string. And since I cannot use a CStringLen
as a return value in FFI.
What type should I use to able to accomplish this?
The type signature of the internal assembly function:
assembly :: String -> ByteString
Here is an example of input and output of this function:
Input:
decl r0 0x02
decl r1 0x10
add r0 r1
mov rr rs
Output (Binary data represented as hexadecimal with 3 bytes per row):
01 00 02
01 01 10
03 00 01
02 05 04