Skip to content

Instantly share code, notes, and snippets.

Created November 25, 2013 17:18
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 anonymous/7644960 to your computer and use it in GitHub Desktop.
Save anonymous/7644960 to your computer and use it in GitHub Desktop.
calling Go function from C
#include "_cgo_export.h"
unsigned long long
cfunc(unsigned int aui, unsigned long long aull) {
return GoFunc( aui, aull);
}
package main
// unsigned long long cfunc(unsigned int aui, unsigned long long aull);
import "C"
import (
"fmt"
)
//export GoFunc
func GoFunc( aui uint, aui64 uint64) uint64 {
return aui64 + uint64(aui)
}
func main() {
ui := 7
ull := uint64(0x4000300020001000)
out := uint64( C.cfunc( C.uint(ui), C.ulonglong(ull)))
fmt.Printf( "expected : %16x \ngot : %16x", uint64(ui) + ull, out)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment