codekingpro/portable-devtools
114k
1// run2 3// Copyright 2022 The Go Authors. All rights reserved.4// Use of this source code is governed by a BSD-style5// license that can be found in the LICENSE file.6 7package main8 9import (10 "fmt"11 "reflect"12 "unsafe"13)14 15func main() {16 var s = "abc"17 sh1 := (*reflect.StringHeader)(unsafe.Pointer(&s))18 ptr2 := unsafe.Pointer(unsafe.StringData(s))19 if ptr2 != unsafe.Pointer(sh1.Data) {20 panic(fmt.Errorf("unsafe.StringData ret %p != %p", ptr2, unsafe.Pointer(sh1.Data)))21 }22}23 