More than 5 years have passed since last update.
OCaml初心者が悩んだ、Cにコールバックしてもらう関数の定義
1
Last updated at Posted at 2015-02-14
背景
ctypesで関数ポインタをC側に渡し、コールバックしてもらうユースケースで
問題となった。
Cから呼びたい型
以下のコードでC側からは
int hoge(char*p)
という関数としてコードを呼び出したい。
悩んだこと
引数と返り値の型をなんとかしたい。
let f x =
begin
print_string x;
-1;
end;;
糖衣構文でやり過ごせた。
引数xの方はprint_stringでstring型にできた。
-1とすることで返り値は符号付きのint型として
OCamlのコンパイラに認めてもらえた。
関連投稿
関連記事
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme
