Getting constants from #defines

Simon Marlow simonmar at
Wed Jun 26 09:20:52 EDT 2002

> I was expecting something like
> foreign import ccall unsafe "static ncurses.h ERR" cERR :: CInt
> to allow me to access the value of ERR (a #define) as cERR. 
> However, as
> far as I can tell GHC is trying to compile this as if ERR was a
> function. This seems silly to me as a function can always be defined
> with a type "a -> b" where "a", "b" or both can be "()" so this should
> be unambiguous.

The FFI doesn't have support for grabbing the values of #defines - you need to use another tool to do this (autoconf, hsc2hs, c2hs, green-card, hdirect, whatever).

The declaration above binds cERR to a function of zero arguments.  i.e. in C-speak this would be 

	void cERR( void );

A function of type a->b has one argument of type 'a', not zero.


More information about the FFI mailing list