Debian Codegraph @

_test/unsafe4.go

raw symbols SCIP
1 package main
2
3 import (
4 "fmt"
5 "math/bits"
6 "unsafe"
7 )
8
9 const WSize = bits.UintSize / 8
10
11 type S struct {
12 X int
13 Y int
14 Z int
15 }
16
17 func main() {
18 arr := []S{
19 {X: 1},
20 {X: 2},
21 {X: 3},
22 }
23 addr := unsafe.Pointer(&arr[0])
24 // s := *(*S)(unsafe.Pointer(uintptr(addr) + SSize*2))
25 s := *(*S)(unsafe.Pointer(uintptr(addr) + WSize*6))
26
27 fmt.Println(s.X)
28 }
29
30 // Output:
31 // 3