Skip to content

Instantly share code, notes, and snippets.

@jamesrr39
Last active February 25, 2016 21:26
Show Gist options
  • Save jamesrr39/c21446489f10c9383349 to your computer and use it in GitHub Desktop.
Save jamesrr39/c21446489f10c9383349 to your computer and use it in GitHub Desktop.
Cgo practice
Some Go/Cgo code
go run cgo.go
# liteide
cgo-learning
package main
/*
// C code
// This should end on the line right above 'import "C"'
// putting a line space between will result in a compile error
extern void print78();
int seventyEight = 78;
int i = 65;
int getEightyFour(){
return 84;
}
*/
import "C"
import "fmt"
func main() {
fmt.Println("cgo!")
fmt.Println(int(C.i))
print78()
fmt.Println(C.getEightyFour())
}
func print78() {
fmt.Println(C.seventyEight)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment