aboutsummaryrefslogtreecommitdiffhomepage
path: root/testdata/cgo/main.go
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2019-04-20 02:39:31 +0200
committerRon Evans <[email protected]>2019-04-20 10:18:38 +0200
commit21a4c14e86e5f30ff3c8ed509f6b2d0f408df08b (patch)
treec94c5898ee0295c5b9c55776a5c20d4b10df87d5 /testdata/cgo/main.go
parentb716cf1afdb6365cbbeb4af974c27c916db36a9a (diff)
downloadtinygo-21a4c14e86e5f30ff3c8ed509f6b2d0f408df08b.tar.gz
tinygo-21a4c14e86e5f30ff3c8ed509f6b2d0f408df08b.zip
cgo: implement C.struct_ types
These types (called elaborated types in C) are used as part of linked lists, among others. This is part an extra feature (to be compatible with CGo C.struct_ types) and part a bugfix: linked lists would result in endless recursion leading to a stack overflow.
Diffstat (limited to 'testdata/cgo/main.go')
-rw-r--r--testdata/cgo/main.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/testdata/cgo/main.go b/testdata/cgo/main.go
index 3f1da8b6d..b722ce107 100644
--- a/testdata/cgo/main.go
+++ b/testdata/cgo/main.go
@@ -53,6 +53,14 @@ func main() {
C.unionSetData(5, 8, 1)
println("union global data:", C.globalUnion.data[0], C.globalUnion.data[1], C.globalUnion.data[2])
println("union field:", printUnion(C.globalUnion).f)
+
+ // recursive types, test using a linked list
+ lastElement := &C.list_t{n: 7, next: nil}
+ list := &C.list_t{n: 3, next: &C.struct_list_t{n: 6, next: (*C.struct_list_t)(lastElement)}}
+ for list != nil {
+ println("n in chain:", list.n)
+ list = (*C.list_t)(list.next)
+ }
}
func printUnion(union C.joined_t) C.joined_t {