cgo: add support for nested structs and unions

This commit is contained in:
Ayke van Laethem
2019-11-07 20:25:51 +01:00
committed by Ron Evans
parent 6108ee6859
commit b153bd63f2
5 changed files with 87 additions and 12 deletions
+5
View File
@@ -80,6 +80,11 @@ func main() {
var _ C.point2d_t = C.point2d_t{x: 3, y: 5}
var _ C.point3d_t = C.point3d_t{x: 3, y: 5, z: 7}
// nested structs/unions
var _ C.tagged_union_t
var _ C.nested_struct_t
var _ C.nested_union_t
// 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 {
+25
View File
@@ -43,6 +43,31 @@ typedef struct {
int z;
} point3d_t;
typedef struct {
int tag;
union {
int a;
int b;
} u;
} tagged_union_t;
typedef struct {
int x;
struct {
char red;
char green;
char blue;
} color;
} nested_struct_t;
typedef union {
int x;
struct {
char a;
char b;
};
} nested_union_t;
// linked list
typedef struct list_t {
int n;