A very simple example to show you how to write a c function in go.
Table of Contents
Here is a very simple c code example,
int Add(int a, int b){
return a+b;
To implement in go, use import "C"
,
package main
/*
int Add(int a, int b){
return a+b;
}
*/
import "C"
import "fmt"
func main() {
a := C.int(10)
b := C.int(20)
c := C.Add(a, b)
fmt.Printf("I'm printing the sum from go: %v\n", c)
}
go run main.go
The output is,
I'm printing the sum from go: 30