cgo: add support for anonymous structs

This commit is contained in:
Ayke van Laethem
2019-06-02 16:22:27 +02:00
committed by Ron Evans
parent 1047c9bd05
commit 0ce4d90779
4 changed files with 125 additions and 83 deletions
+5 -1
View File
@@ -71,9 +71,13 @@ func main() {
printBitfield(&C.globalBitfield)
// elaborated type
p := C.struct_point{x: 3, y: 5}
p := C.struct_point2d{x: 3, y: 5}
println("struct:", p.x, p.y)
// multiple anonymous structs (inside a typedef)
var _ C.point2d_t = C.point2d_t{x: 3, y: 5}
var _ C.point3d_t = C.point3d_t{x: 3, y: 5, z: 7}
// recursive types, test using a linked list
list := &C.list_t{n: 3, next: &C.struct_list_t{n: 6, next: &C.list_t{n: 7, next: nil}}}
for list != nil {
+12 -1
View File
@@ -27,11 +27,22 @@ typedef struct collection {
unsigned char c;
} collection_t;
struct point {
struct point2d {
int x;
int y;
};
typedef struct {
int x;
int y;
} point2d_t;
typedef struct {
int x;
int y;
int z;
} point3d_t;
// linked list
typedef struct list_t {
int n;