4 ms·
From http://blog.golang.org/2011/03/c-go-cgo.html http://blog.golang.org/2011/03/c-go-cgo.html : package rand /* #include <stdlib.h> */ import "C"
by jkn 15y ago
From http://blog.golang.org/2011/03/c-go-cgo.html http://blog.golang.org/2011/03/c-go-cgo.html :
package rand
/*
#include <stdlib.h>
*/
import "C"
func Random() int {
return int(C.random())
}
func Seed(i int) {
C.srandom(C.uint(i))
}
So calling C functions from Go is very easy. However the other way is not supported, AFAIK.
- luriel 15y agoCalling Go from C is supported, but is not quite as straightforward. You can also use SWIG.