Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
haskell: get address of a haskell function (at runtime)
void func(void);
unsigned long getFuncAddr(void)
return (unsigned long) func;
{-# LANGUAGE ForeignFunctionInterface #-}
module Main where
import Foreign
import Foreign.C.Types
import Text.Printf
foreign import ccall "getFuncAddr"
getFuncAddr :: CULong
main :: IO ()
main = do
printf "0x%016x\n" (fromIntegral getFuncAddr :: Word64)
foreign export ccall func :: IO ()
func :: IO ()
func = do
printf "hello world\n"
all: main
objdump -D $< | grep '<func>'
main: main.hs ffi.c
ghc --make -O2 $^ -o $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.