|
1 | 1 | <!--{
|
2 | 2 | "Title": "The Go Programming Language Specification",
|
3 |
| - "Subtitle": "Version of Apr 20, 2021", |
| 3 | + "Subtitle": "Version of Apr 21, 2021", |
4 | 4 | "Path": "/ref/spec"
|
5 | 5 | }-->
|
6 | 6 |
|
@@ -6711,6 +6711,10 @@ <h3 id="Package_unsafe">Package <code>unsafe</code></h3>
|
6711 | 6711 | func Alignof(variable ArbitraryType) uintptr
|
6712 | 6712 | func Offsetof(selector ArbitraryType) uintptr
|
6713 | 6713 | func Sizeof(variable ArbitraryType) uintptr
|
| 6714 | + |
| 6715 | +type IntegerType int // shorthand for an integer type; it is not a real type |
| 6716 | +func Add(ptr Pointer, len IntegerType) Pointer |
| 6717 | +func Slice(ptr *ArbitraryType, len IntegerType) []ArbitraryType |
6714 | 6718 | </pre>
|
6715 | 6719 |
|
6716 | 6720 | <p>
|
@@ -6767,6 +6771,32 @@ <h3 id="Package_unsafe">Package <code>unsafe</code></h3>
|
6767 | 6771 | <code>Sizeof</code> are compile-time constant expressions of type <code>uintptr</code>.
|
6768 | 6772 | </p>
|
6769 | 6773 |
|
| 6774 | +<p> |
| 6775 | +The function <code>Add</code> adds <code>len</code> to <code>ptr</code> |
| 6776 | +and returns the updated pointer <code>unsafe.Pointer(uintptr(ptr) + uintptr(len))</code>. |
| 6777 | +The <code>len</code> argument must be of integer type or an untyped <a href="#Constants">constant</a>. |
| 6778 | +A constant <code>len</code> argument must be <a href="#Representability">representable</a> by a value of type <code>int</code>; |
| 6779 | +if it is an untyped constant it is given type <code>int</code>. |
| 6780 | +The rules for <a href="/pkg/unsafe#Pointer">valid uses</a> of <code>Pointer</code> still apply. |
| 6781 | +</p> |
| 6782 | + |
| 6783 | +<p> |
| 6784 | +The function <code>Slice</code> returns a slice whose underlying array starts at <code>ptr</code> |
| 6785 | +and whose length and capacity are <code>len</code>: |
| 6786 | +</p> |
| 6787 | + |
| 6788 | +<pre> |
| 6789 | +(*[len]ArbitraryType)(unsafe.Pointer(ptr))[:] |
| 6790 | +</pre> |
| 6791 | + |
| 6792 | +<p> |
| 6793 | +The <code>len</code> argument must be of integer type or an untyped <a href="#Constants">constant</a>. |
| 6794 | +A constant <code>len</code> argument must be non-negative and <a href="#Representability">representable</a> by a value of type <code>int</code>; |
| 6795 | +if it is an untyped constant it is given type <code>int</code>. |
| 6796 | +If <code>ptr</code> is <code>nil</code> or <code>len</code> is negative at run time, |
| 6797 | +a <a href="#Run_time_panics">run-time panic</a> occurs. |
| 6798 | +</p> |
| 6799 | + |
6770 | 6800 | <h3 id="Size_and_alignment_guarantees">Size and alignment guarantees</h3>
|
6771 | 6801 |
|
6772 | 6802 | <p>
|
|
0 commit comments