Created
November 25, 2013 17:18
-
-
Save anonymous/7644960 to your computer and use it in GitHub Desktop.
calling Go function from C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "_cgo_export.h" | |
unsigned long long | |
cfunc(unsigned int aui, unsigned long long aull) { | |
return GoFunc( aui, aull); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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