cgo: do not rely on stdint.h to be available

This commit is contained in:
Ayke van Laethem
2018-11-30 12:45:38 +01:00
parent 0af7da9bff
commit c6069476a7
4 changed files with 40 additions and 24 deletions
+1 -7
View File
@@ -1,13 +1,7 @@
#include <stdint.h>
int32_t fortytwo() {
int fortytwo() {
return 42;
}
int add(int a, int b) {
return a + b;
}
int32_t mul(int32_t a, int32_t b) {
return a * b;
}
+5 -5
View File
@@ -1,20 +1,20 @@
package main
/*
#include <stdint.h>
int32_t fortytwo(void);
int32_t mul(int32_t a, int32_t b);
typedef int32_t myint;
int fortytwo(void);
typedef short myint;
int add(int a, int b);
*/
import "C"
import "unsafe"
func main() {
println("fortytwo:", C.fortytwo())
println("mul:", C.mul(C.int32_t(3), 5))
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)
}
+1 -1
View File
@@ -1,5 +1,5 @@
fortytwo: 42
mul: 15
add: 8
myint: 3 5
myint size: 2
longlong: -1099511627776