I'm confused about the behavior when appending to a slice which already has the max possible size.
As far as my understanding goes a slice can either have a max size of int32 or int64 depending on your system.
When executing test := make([]struct{},math.MaxInt64+1)
I get the error len argument too large in make([]struct {})
which is within my expectations.
But when doing something like:
test := make([]struct{},math.MaxInt64)
for i:=0;i<100 ; i++ {
test = append(test, struct{}{})
}
fmt.Println(len(test))
I expect the program to panic but surprisingly the code runs with out any problems and len
returns an overflowed value with -9223372036854775709
.
Could someone maybe elaborate the behavior?
(I'm using go1.11.2 linux/amd64)