mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-05 19:43:44 +00:00
cgo: add support for anonymous structs
This commit is contained in:
committed by
Ron Evans
parent
1047c9bd05
commit
0ce4d90779
Vendored
+5
-1
@@ -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 {
|
||||
|
||||
Vendored
+12
-1
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user