shithub: MicroHs

ref: 7d2f32a9e5e2b27faa217fd3d9d2d2092f052861
dir: /tests/ForeignC.hs/

View raw version
module ForeignC(main) where
import Prelude
import Foreign.C.Types
import Foreign.Ptr
import Foreign.Storable

foreign import ccall "llabs" iabs :: Int -> IO Int
foreign import ccall "sys/errno.h &errno" cerrno :: IO (Ptr CInt)
foreign import ccall "&llabs" pabs :: IO (FunPtr (Int -> IO Int))

main :: IO ()
main = do
  x1 <- iabs (3 - 8)
  putStrLn $ show x1
  x2 <- iabs (10 - 8)
  putStrLn $ show x2
  p <- cerrno
  CInt e <- peek p
  print e