Exporting a String
Marcin 'Qrczak' Kowalczyk
28 Sep 2001 10:30:13 GMT
Fri, 28 Sep 2001 08:20:08 +0200, Sven Eric Panitz <firstname.lastname@example.org> pisze:
> xs <- peekCString cxs
> ys <- peekCString cys
> erg <- return (xs++ys)
The last line can be written:
let erg = xs++ys
and you can also directly write (xs++ys) instead of erg below.
> newCString erg
All OK, except that you leak memory. This string is allocated using
malloc and should be freed using free when no longer needed (either
C free or Haskell free).
> //calling Haskell function
> test=cAppend("the world"," is my oyster");
> //printing its result
> printf("%s\n", test);
And then: free(test);
BTW, there is less boilerplate (no startupHaskell etc.) when the main
program is in Haskell instead of C (of course sometimes this is not
what we want).
__("< Marcin Kowalczyk * email@example.com http://qrczak.ids.net.pl/
^^ SYGNATURA ZASTĘPCZA