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
I tried to use noinit with a []byte slice, but the parser complained that field must be a pointer to have noinit. It seems a bit unnecessary to insist on having a pointer to a slice, since a slice in itself can be nil. Consider the following code:
package main
import "fmt"
type Lala struct {
Blah []byte
}
func main() {
lala := Lala{}
if lala.Blah == nil {
fmt.Println("Blah is nil")
}
lala.Blah = []byte{}
if lala.Blah != nil {
fmt.Println("Blah is not nil")
}
}
The result is:
Blah is nil
Blah is not nil
The text was updated successfully, but these errors were encountered:
I tried to use
noinit
with a[]byte
slice, but the parser complained thatfield must be a pointer to have noinit
. It seems a bit unnecessary to insist on having a pointer to a slice, since a slice in itself can benil
. Consider the following code:The result is:
The text was updated successfully, but these errors were encountered: