Confused by FFI

Ian Lynagh igloo at earth.li
Fri Jul 19 12:06:27 EDT 2002


On Mon, Jul 08, 2002 at 07:19:04PM +0100, Ian Lynagh wrote:
> 
> I was expecting the Haskell program and C program attached to produce
> the same results. However, as shown below, the C program gives identical
> values for the two pointers whereas the Haskell program gives different
> ones.
> 
> $ ./c
> 0x0804f050
> 0x0804f050
> 0
> $ ./h
> 0x08084970
> 0x0807eba8
> 0
> 
> Does anyone know what is going on here?

And naturally it's blindingly obvious now I see what's going on.

> import Ptr
> data Window = Window
> type PWindow = Ptr Window
> 
> foreign import ccall unsafe "static ncurses.h &stdscr" stdscr :: PWindow

The Haskell stdscr is actually returning a Ptr PWindow and you have to
peek at it to see where the actual pointer is currently pointing.


Have fun
Ian




More information about the Glasgow-haskell-bugs mailing list