| I want to pass a String to a function which is imported from C code:
|       foreign import  "pass" prim_pass :: String -> String
| The declaration above gives me an error from ghc like "String 
| type not 
| supported for imported functions".
| I thought that String being [Char] should be supported 
| (somehow like a 
| definition with "newtype" keyword).
| Can you tell me how can I pass strings to and from C code, as 
| simple as 
| possible (I know about HDirect, but I couldn't make it work 
| for me: red-hat 
| 7.1, ghc 5.00)?

First of all, upgrade to 5.00.2, since it is significantly less
buggy than 5.00.


int fooble ( char* str, int n )
{
   fprintf(stderr, "fooble called: %s %d\n", str, n );
   return 42;
}


import PrelByteArr
import PrelPack         (packString)

foreign import "fooble" fooble
   fooble :: PackedString -> Int -> IO Int

type PackedString = ByteArray Int

main = do n <- fooble (packString "hello, C world") 99
          putStrLn ("Returned value is " ++ show n)

For more examples read the compiler sources, at 
fptools/ghc/compiler/ghci/Linker.lhs.

J

_______________________________________________
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

Reply via email to