mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-04 19:17:47 +00:00
loader: support global variables in CGo (#173)
Global variables (like functions) must be declared in the import "C" preamble and can then be used from Go.
This commit is contained in:
Vendored
+2
@@ -1,5 +1,7 @@
|
||||
#include "main.h"
|
||||
|
||||
int global = 3;
|
||||
|
||||
int fortytwo() {
|
||||
return 42;
|
||||
}
|
||||
|
||||
Vendored
+1
@@ -16,4 +16,5 @@ func main() {
|
||||
println("myint size:", int(unsafe.Sizeof(x)))
|
||||
var y C.longlong = -(1 << 40)
|
||||
println("longlong:", y)
|
||||
println("global:", C.global)
|
||||
}
|
||||
|
||||
Vendored
+1
@@ -1,2 +1,3 @@
|
||||
typedef short myint;
|
||||
int add(int a, int b);
|
||||
extern int global;
|
||||
|
||||
Vendored
+1
@@ -3,3 +3,4 @@ add: 8
|
||||
myint: 3 5
|
||||
myint size: 2
|
||||
longlong: -1099511627776
|
||||
global: 3
|
||||
|
||||
Reference in New Issue
Block a user