Last active
February 25, 2016 21:26
-
-
Save jamesrr39/c21446489f10c9383349 to your computer and use it in GitHub Desktop.
Cgo practice
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
Some Go/Cgo code | |
go run cgo.go |
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
# liteide | |
cgo-learning |
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 | |
/* | |
// 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