[Haskell-cafe] Regarding Haskell FFI for C/C++ (Passing of String)

rajendra prasad rajendradprasad at gmail.com
Tue Mar 27 09:43:11 CEST 2012


Thanks Yves for the reply.
The link provided by you is very helpful.

Thank you very much.

Regards,
Rajendra

On Thu, Mar 22, 2012 at 7:53 PM, Yves Parès <yves.pares at gmail.com> wrote:

> (Sorry for the double post)
>
> Forget about ByteString.Char8: it doesn't handle unicode as it truncates
> characters.
>
> Going from String to bytestring is easy thanks to the utf8-string (
> http://hackage.haskell.org/packages/archive/utf8-string/0.3.7/doc/html/Codec-Binary-UTF8-String.html)
> package and pack function from Data.ByteString(.Lazy).
>
> And if you want to convert your String directly to a CString (a Ptr CChar)
> you better use Foreign.C.String.withCString.
>
> Le 22 mars 2012 15:17, Yves Parès <yves.pares at gmail.com> a écrit :
>
> This joins the question I asked two days ago here. (See
>> http://haskell.1045720.n5.nabble.com/Quickest-way-to-pass-Text-to-C-code-td5582223.html
>> )
>> Hope that helps.
>>
>> Le 22 mars 2012 15:10, rajendra prasad <rajendradprasad at gmail.com> a
>> écrit :
>>
>>> Hi,
>>>
>>> I have just started learning Haskell FFI. I am trying to send a string
>>> from hastell to a C function. For this, I am required to convert the
>>> haskell string to byte string. I have two methods to achieve this task.
>>> Both are listed below:
>>>
>>> 1) import Foreign.C.String
>>>     let arg1 = map castCharToCChar "Hello" :: [CChar]
>>>
>>> 2) import qualified Data.ByteString.Char8 as B
>>>     f = B.pack "Hello"
>>>
>>> I just wanted to know the optimal way to achieve this task. Please
>>> suggest the optimal way of doing this. If there is any other way, please
>>> share it.
>>>
>>> Also, please suggest me any good tutorial to start with Haskell FFI for
>>> C/C++.
>>>
>>> Thank you very much.
>>>
>>>
>>> Regards,
>>> Rajendra
>>>
>>> _______________________________________________
>>> Haskell-Cafe mailing list
>>> Haskell-Cafe at haskell.org
>>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120327/eb230552/attachment-0001.htm>


More information about the Haskell-Cafe mailing list