Ticket #677: MemBug.hs

File MemBug.hs, 403 bytes (added by simonmar, 10 years ago)
Line 
1import Foreign
2import Foreign.C
3import Char
4import Monad
5
6main = haskellFunc
7
8haskellFunc :: IO ()
9haskellFunc = allocaBytes 100 $ \ptr -> do
10  pokeArray ptr (replicate 100 68)
11  cFunc ptr
12  elems <- peekArray 100 ptr
13  putStrLn (reverse (map (chr . fromIntegral) elems))
14
15foreign import ccall safe "membug.h cFunc" cFunc :: Ptr CChar -> IO ()
16
17foreign export ccall "haskellFunc" haskellFunc :: IO ()
18
19