[Haskell-cafe] C variable access via FFI

Bertram Felgenhauer bertram.felgenhauer at googlemail.com
Tue Apr 20 06:13:07 EDT 2010

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,

Yes it is, as explained in section 4.1.1. in the FFI specification [1].
An import for a global variable  int bar  would look like this:

    foreign import ccall "&bar" bar :: Ptr CInt 

The difference to an import of a function  int foo()  is the extra "&".



[1] http://www.cse.unsw.edu.au/~chak/haskell/ffi/ffi/ffise4.html#x7-170004.1.1

More information about the Haskell-Cafe mailing list