Skip to content

@lewurm /.gitignore
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
haskell: get address of a haskell function (at runtime)
*.hi
*_stub.h
*.o
main
http://stackoverflow.com/questions/10967598/get-the-address-of-a-function-without-ffi
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.