diff --git a/doc/go_spec.html b/doc/go_spec.html index 29109b6b9e..764dcd2f78 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -5530,16 +5530,23 @@ runes("白鵬翔") // []rune{0x767d, 0x9d6c, 0x7fd4} -

Conversions from slice to array pointer

+

Conversions from slice to array or array pointer

-Converting a slice to an array pointer yields a pointer to the underlying array of the slice. -If the length of the slice is less than the length of the array, +Converting a slice to an array yields an array containing the elements of the underlying array of the slice. +Similarly, converting a slice to an array pointer yields a pointer to the underlying array of the slice. +In both cases, if the length of the slice is less than the length of the array, a run-time panic occurs.

 s := make([]byte, 2, 4)
+
+a0 := ([0]byte)(s)
+a1 := ([1]byte)(s[1:])   // a1[0] == s[1]
+a2 := ([2]byte)(s)       // a2[0] == s[0]
+a4 := ([4]byte)(s)       // panics: len([4]byte) > len(s)
+
 s0 := (*[0]byte)(s)      // s0 != nil
 s1 := (*[1]byte)(s[1:])  // &s1[0] == &s[1]
 s2 := (*[2]byte)(s)      // &s2[0] == &s[0]