RE: Getting constants from #defines
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. Cheers, Simon
On Wed, Jun 26, 2002 at 02:20:52PM +0100, Simon Marlow wrote:
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).
OK, I'll have a look at these.
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.
OK, I thought I'd seen something of type int foo(void) given a Haskell type () -> IO CInt, but I can't find it now so I probably imagined it. And now I think about it I already have loads of functions whose type is just IO something. Thanks Ian
participants (2)
-
Ian Lynagh -
Simon Marlow