Skip to content

Commit

Permalink
add test of string pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
mlycore committed Dec 19, 2017
1 parent 3748723 commit adb365b
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions string/demo1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package main
import(
"fmt"
"reflect"
"unsafe"
)

func pp(ptr interface{}) {
p := reflect.ValueOf(ptr).Pointer()
h := (*uintptr)(unsafe.Pointer(p))
fmt.Printf("%x\n", *h)

}

func main() {
s := "abcdefg"
s1 := s[:3]

fmt.Printf("%#v\n", (*reflect.StringHeader)(unsafe.Pointer(&s)))
fmt.Printf("%#v\n", (*reflect.StringHeader)(unsafe.Pointer(&s1)))

ptr := &s
pp(ptr)
}

0 comments on commit adb365b

Please sign in to comment.