
Global variables (like functions) must be declared in the import "C" preamble and can then be used from Go.
20 строки
362 Б
Go
20 строки
362 Б
Go
package main
|
|
|
|
/*
|
|
int fortytwo(void);
|
|
#include "main.h"
|
|
*/
|
|
import "C"
|
|
|
|
import "unsafe"
|
|
|
|
func main() {
|
|
println("fortytwo:", C.fortytwo())
|
|
println("add:", C.add(C.int(3), 5))
|
|
var x C.myint = 3
|
|
println("myint:", x, C.myint(5))
|
|
println("myint size:", int(unsafe.Sizeof(x)))
|
|
var y C.longlong = -(1 << 40)
|
|
println("longlong:", y)
|
|
println("global:", C.global)
|
|
}
|