-
-
Save qnikst/f807cdc412d6b9c3c3effeaf31d544ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gcc -c tc.c -g -ggdb -c | |
ghc T.hs tc.o -g |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(gdb) bt | |
#0 0x00007fbbf1c0f380 in __read_nocancel () at ../sysdeps/unix/syscall-template.S:84 | |
#1 0x00007fbbf1ba6c08 in _IO_new_file_underflow (fp=0x7fbbf1ec64e0 <_IO_2_1_stdin_>) at fileops.c:592 | |
#2 0x00007fbbf1ba7a6e in __GI__IO_default_uflow (fp=0x7fbbf1ec64e0 <_IO_2_1_stdin_>) at genops.c:413 | |
#3 0x00007fbbf1b8aa73 in _IO_vfscanf_internal (s=<optimized out>, format=<optimized out>, argptr=argptr@entry=0x7fff40865458, | |
errp=errp@entry=0x0) at vfscanf.c:634 | |
#4 0x00007fbbf1b98a4b in __isoc99_scanf (format=<optimized out>) at isoc99_scanf.c:37 | |
#5 0x0000000000405d4f in another () at tc.c:6 | |
#6 0x000000000040569d in r2nL_info () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE ForeignFunctionInterface #-} | |
import Foreign | |
import Foreign.C | |
foreign import ccall "wrapper" cwrap :: (CInt -> IO CInt) -> IO (FunPtr (CInt -> IO CInt)) | |
foreign import ccall "inside" inside :: FunPtr (CInt -> IO CInt) -> IO () | |
foreign import ccall "another" another :: IO () | |
waiting :: CInt -> IO CInt | |
waiting i = print i >> another >> return 27 | |
main = do | |
p <- cwrap waiting | |
inside p |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void another() { | |
int i; | |
printf("here\n"); | |
scanf("%i", &i); | |
} | |
void other(int (*f)(int)) { | |
f(42); | |
} | |
void inside(int (*f)(int)) { | |
other(f); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment