mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-06 20:13:40 +00:00
cgo: add support for nested structs and unions
This commit is contained in:
committed by
Ron Evans
parent
6108ee6859
commit
b153bd63f2
Vendored
+5
@@ -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 {
|
||||
|
||||
Vendored
+25
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user