Debian Codegraph @

test/unsafe_slice_data.go

raw
1 // run
2
3 // Copyright 2022 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
6
7 package main
8
9 import (
10 "fmt"
11 "reflect"
12 "unsafe"
13 )
14
15 func main() {
16 var s = []byte("abc")
17 sh1 := *(*reflect.SliceHeader)(unsafe.Pointer(&s))
18 ptr2 := unsafe.Pointer(unsafe.SliceData(s))
19 if ptr2 != unsafe.Pointer(sh1.Data) {
20 panic(fmt.Errorf("unsafe.SliceData %p != %p", ptr2, unsafe.Pointer(sh1.Data)))
21 }
22 }