Why does the following program crash?
package main
import "fmt"
import "unsafe"
import "reflect"
func main() {
s := "keep"
hdr := (*reflect.StringHeader)(unsafe.Pointer(&s))
byteSequence := (*byte)(unsafe.Pointer(hdr.Data))
fmt.Println(*byteSequence) // k
*byteSequence = 'j' // crash here
fmt.Println(s) // expect: jeep
}
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.