Last active
August 29, 2015 14:14
-
-
Save yonta/6a120f5632e0b3783e18 to your computer and use it in GitHub Desktop.
SML# test
This file contains hidden or 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 -o hoge.o -c hoge.c | |
smlsharp -o run fuga.sml hoge.o | |
./run |
This file contains hidden or 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
(* できない | |
(type inference 004) not an interoperable type: int | |
ref | |
*) | |
val f1 = _import "hoge" : (int ref -> int) -> () | |
val () = f1 (op !) | |
(* できる、けどptr受け取る関数がSML#では作れないから半分死んでるんじゃ *) | |
(* いや、builtin関数使えばいけるか? *) | |
val f2 = _import "hoge" : (int ptr -> int) -> () | |
val () = f2 (SMLSharp_Builtin.Pointer.deref) | |
(* できる *) | |
val f3 = _import "hoge2" : (int ref) -> () | |
val () = f3 (ref 2) | |
(* できない、公式にptr型相当の返り値を禁止している | |
(type inference 004) not an interoperable type: int | |
ref | |
*) | |
val f4 = _import "hoge3" : (int) -> int ref | |
val () = (print o Int.toString o ! o f4) 0 | |
(* できる *) | |
val f5 = _import "hoge4" : (int -> int ref) -> () | |
val () = f5 (fn x => ref x) |
This file contains hidden or 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
void hoge(void (*f)(int*)) | |
{ | |
return; | |
} | |
#include <stdio.h> | |
void hoge2 (int* n) | |
{ | |
printf("%d\n", *n); | |
} | |
int* hoge3(int n) | |
{ | |
int* p = &n; | |
return p; | |
} | |
void hoge4(int* (*f)(int)) | |
{ | |
printf("%d\n", *(f(0))); | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment