Skip to content

Instantly share code, notes, and snippets.

@kikuchy
Created October 4, 2017 07:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kikuchy/7b656aa46662c783fe2ce539fd9a67b1 to your computer and use it in GitHub Desktop.
Save kikuchy/7b656aa46662c783fe2ce539fd9a67b1 to your computer and use it in GitHub Desktop.
GoからCの関数をコールバック関数として呼び出したい。けどGoからCの関数ポインタを関数として呼び出すことはできない。のでなんとかした。
#include <stdio.h>
#include "worker.h"
void cb(int hoge) {
printf("value: %d\n", hoge);
}
int main() {
DoSomeCallback(cb);
}
package main
//typedef void (*callback)(int);
//
//static inline void invokeCallback(int value, callback f) {
// f(value);
//}
import "C"
import "fmt"
//export DoSomeCallback
func DoSomeCallback(callback C.callback) {
fmt.Println("in go world")
C.invokeCallback(30, callback)
}
func main() {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment