• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
7package main
8
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