You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (go env)?
go env Output
$ go env
set GO111MODULE=on
set GOARCH=amd64
set GOBIN=D:\software\go\bin
set GOCACHE=C:\Users\hao\AppData\Local\go-build
set GOENV=C:\Users\hao\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=D:\software\go\GOPATH\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=D:\software\go\GOPATH
set GOPRIVATE=
set GOPROXY=https://goproxy.io,direct
set GOROOT=D:\software\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=D:\software\go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.17
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=D:\code\golang\personal\github.com\haochen233\go-stdlib-in-action\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\hao\AppData\Local\Temp\go-build803430058=/tmp/go-build -gno-record-gcc-switches
GOROOT/bin/go version: go version go1.17 windows/amd64
GOROOT/bin/go tool compile -V: compile version go1.17
gdb --version: GNU gdb (GDB) 8.1
What did you do?
I try to use package unsafe and reflect to convert string to []byte without memory allocation.
unsafe lets do you unsafe things, but there's no guarantee that the program will crash or panic if you happen to use it wrong. Things will work sometimes, and break some other times.
Nothing special.
The first snippet not working because compiler "mark" string as constant and put it in constant address space where changed are prohibited.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I try to use package unsafe and reflect to convert string to []byte without memory allocation.
normal case:
This will panic, because string are not modifiable.
But, there's a confusing case here
I successfully modified the string, no panic. I'm a little confused.
What did you expect to see?
What did you see instead?
The text was updated successfully, but these errors were encountered: