mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-11 14:33:41 +00:00
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.
This commit is contained in:
committed by
Ron Evans
parent
b716cf1afd
commit
21a4c14e86
Vendored
+8
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user