golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.42k stars 17.59k forks source link

proposal: Go 2: permit converting a string constant to a byte array type #36890

Closed jfcg closed 4 years ago

jfcg commented 4 years ago

byte slices and strings are convertable to each other:

var bs = []byte("şevkı")
fmt.Println(len(bs), string(bs))

I propose to extend this by allowing to convert:

// ok var ba = [7]byte("şevkı")

// pad with zeros var ba = [8]byte("şevkı")



I believe this is backward-compatible with Go 1. What do you think?
ianlancetaylor commented 4 years ago

No change in consensus.

gopherbot commented 4 years ago

Change https://golang.org/cl/245099 mentions this issue: compiler,runtime: pass only ptr and len to some runtime calls