cgo: implement bool/float/complex types

This commit is contained in:
Ayke van Laethem
2019-02-08 19:56:43 +01:00
committed by Ron Evans
parent fab38a0749
commit da345e8723
5 changed files with 64 additions and 14 deletions
+7
View File
@@ -1,6 +1,13 @@
#include "main.h"
int global = 3;
_Bool globalBool = 1;
_Bool globalBool2 = 10; // test narrowing
float globalFloat = 3.1;
double globalDouble = 3.2;
_Complex float globalComplexFloat = 4.1+3.3i;
_Complex double globalComplexDouble = 4.2+3.4i;
_Complex double globalComplexLongDouble = 4.3+3.5i;
int fortytwo() {
return 42;
+8
View File
@@ -28,6 +28,14 @@ func main() {
println("callback 1:", C.doCallback(20, 30, cb))
cb = C.binop_t(C.mul)
println("callback 2:", C.doCallback(20, 30, cb))
// more globals
println("bool:", C.globalBool, C.globalBool2 == true)
println("float:", C.globalFloat)
println("double:", C.globalDouble)
println("complex float:", C.globalComplexFloat)
println("complex double:", C.globalComplexDouble)
println("complex long double:", C.globalComplexLongDouble)
}
//export mul
+10 -1
View File
@@ -3,9 +3,18 @@ int add(int a, int b);
typedef int (*binop_t) (int, int);
int doCallback(int a, int b, binop_t cb);
typedef int * intPointer;
extern int global;
void store(int value, int *ptr);
// test globals
extern int global;
extern _Bool globalBool;
extern _Bool globalBool2;
extern float globalFloat;
extern double globalDouble;
extern _Complex float globalComplexFloat;
extern _Complex double globalComplexDouble;
extern _Complex double globalComplexLongDouble;
// test duplicate definitions
int add(int a, int b);
extern int global;
+6
View File
@@ -8,3 +8,9 @@ global: 3
25: 25
callback 1: 50
callback 2: 600
bool: true true
float: +3.100000e+000
double: +3.200000e+000
complex float: (+4.100000e+000+3.300000e+000i)
complex double: (+4.200000e+000+3.400000e+000i)
complex long double: (+4.300000e+000+3.500000e+000i)