
I am trying to figure out how to pass array of String (char **) from C to Haskell? I have read the FFI examples, but most of them are centered on calling C from Haskell. I have read in the mailing list, it is rare to call Haskell from C, but my requirement is such that I am going to write Haskell library that needs to be called from C. Also, I read that the linking in FFI needs to be done through ghc. However, I have an existing Make system that uses gcc to do the linking, so what extra steps I need to do make gcc do the linking instead? Anurag

On Fri, Mar 14, 2008 at 09:54:11PM +0800, Verma Anurag-VNF673 wrote:
I am trying to figure out how to pass array of String (char **) from C to Haskell? I have read the FFI examples, but most of them are centered on calling C from Haskell. I have read in the mailing list, it is rare to call Haskell from C, but my requirement is such that I am going to write Haskell library that needs to be called from C.
here is a simple example. the first argument is the number of strings, the second is the pointer. The same code will work whether you are calling C from haskell or vice versa. getargs :: Int -> (Ptr CString) -> IO [String] getArgs argc argv = do let f n = peekElemOff argv n >>= peekCString mapM f [0 .. fromIntegral argc - 1] John -- John Meacham - ⑆repetae.net⑆john⑈
participants (2)
-
John Meacham
-
Verma Anurag-VNF673