[Haskell-cafe] C variable access via FFI

John Meacham john at repetae.net
Tue Apr 20 18:27:32 EDT 2010


On Tue, Apr 20, 2010 at 01:48:16AM -0500, Tom Hawkins wrote:
> I have a bunch of global variables in C I would like to directly read
> and write from Haskell.  Is this possible with FFI, or must I write a
> bunch of C wrapper functions for the interface, i.e. a 'get' and a
> 'set' for each variable?

Yup. 

foo.c:
  int my_int;

Foo.hs:

foreign import "&my_int" my_int_ptr :: Ptr Int

foo = do
        poke my_int_ptr 4
        x <- peek my_int_Ptr


        John

-- 
John Meacham - ⑆repetae.net⑆john⑈ - http://notanumber.net/


More information about the Haskell-Cafe mailing list