blob: 57b59050f192126a51fa611eef3aace44216f2aa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
struct Struct {
name string
x int
}
fn main() {
unsafe {
pb := &byte(0)
ppb := &&byte(0)
pppb := &&&byte(0)
ppppb := &&&&byte(0)
dump(voidptr(pb))
dump(voidptr(ppb))
dump(voidptr(pppb))
dump(voidptr(ppppb))
pc := &char(0)
ppc := &&char(0)
pppc := &&&char(0)
ppppc := &&&&char(0)
dump(voidptr(pc))
dump(voidptr(ppc))
dump(voidptr(pppc))
dump(voidptr(ppppc))
ps := &Struct(0)
pps := &&Struct(0)
ppps := &&&Struct(0)
pppps := &&&&Struct(0)
dump(voidptr(ps))
dump(voidptr(pps))
dump(voidptr(ppps))
dump(voidptr(pppps))
}
ss := &Struct{
name: 'abc'
x: 123
}
dump(ss)
pss := voidptr(ss)
if &Struct(pss).name == 'abc' {
println('ok')
}
if &Struct(pss).x == 123 {
// &Struct cast and selecting .x
println('ok')
}
if &&Struct(pss) != 0 {
// &&Struct
println('ok')
}
}
|