aboutsummaryrefslogtreecommitdiff
path: root/doc/go_spec.html
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2021-04-21 00:12:02 -0700
committerMatthew Dempsky <mdempsky@google.com>2021-04-22 22:03:10 +0000
commit1da05eb0cebed9595ee0d326d9bd67edd046af0d (patch)
tree88bc7e65daba7b8e3661fd00e16be80dce9a428e /doc/go_spec.html
parent74059685fda0b60d539450ad6b7331ade838e90c (diff)
downloadgo-1da05eb0cebed9595ee0d326d9bd67edd046af0d.tar.gz
go-1da05eb0cebed9595ee0d326d9bd67edd046af0d.zip
spec: add unsafe.Add and unsafe.Slice
Updates #19367. Updates #40481. Change-Id: I578066ad68d2cd6bea50df1a534cf799e4404a7f Reviewed-on: https://go-review.googlesource.com/c/go/+/312212 Trust: Matthew Dempsky <mdempsky@google.com> Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'doc/go_spec.html')
-rw-r--r--doc/go_spec.html32
1 files changed, 31 insertions, 1 deletions
diff --git a/doc/go_spec.html b/doc/go_spec.html
index 13b8beb06c..bbcdd54b02 100644
--- a/doc/go_spec.html
+++ b/doc/go_spec.html
@@ -1,6 +1,6 @@
<!--{
"Title": "The Go Programming Language Specification",
- "Subtitle": "Version of Apr 20, 2021",
+ "Subtitle": "Version of Apr 21, 2021",
"Path": "/ref/spec"
}-->
@@ -6711,6 +6711,10 @@ type Pointer *ArbitraryType
func Alignof(variable ArbitraryType) uintptr
func Offsetof(selector ArbitraryType) uintptr
func Sizeof(variable ArbitraryType) uintptr
+
+type IntegerType int // shorthand for an integer type; it is not a real type
+func Add(ptr Pointer, len IntegerType) Pointer
+func Slice(ptr *ArbitraryType, len IntegerType) []ArbitraryType
</pre>
<p>
@@ -6767,6 +6771,32 @@ Calls to <code>Alignof</code>, <code>Offsetof</code>, and
<code>Sizeof</code> are compile-time constant expressions of type <code>uintptr</code>.
</p>
+<p>
+The function <code>Add</code> adds <code>len</code> to <code>ptr</code>
+and returns the updated pointer <code>unsafe.Pointer(uintptr(ptr) + uintptr(len))</code>.
+The <code>len</code> argument must be of integer type or an untyped <a href="#Constants">constant</a>.
+A constant <code>len</code> argument must be <a href="#Representability">representable</a> by a value of type <code>int</code>;
+if it is an untyped constant it is given type <code>int</code>.
+The rules for <a href="/pkg/unsafe#Pointer">valid uses</a> of <code>Pointer</code> still apply.
+</p>
+
+<p>
+The function <code>Slice</code> returns a slice whose underlying array starts at <code>ptr</code>
+and whose length and capacity are <code>len</code>:
+</p>
+
+<pre>
+(*[len]ArbitraryType)(unsafe.Pointer(ptr))[:]
+</pre>
+
+<p>
+The <code>len</code> argument must be of integer type or an untyped <a href="#Constants">constant</a>.
+A constant <code>len</code> argument must be non-negative and <a href="#Representability">representable</a> by a value of type <code>int</code>;
+if it is an untyped constant it is given type <code>int</code>.
+If <code>ptr</code> is <code>nil</code> or <code>len</code> is negative at run time,
+a <a href="#Run_time_panics">run-time panic</a> occurs.
+</p>
+
<h3 id="Size_and_alignment_guarantees">Size and alignment guarantees</h3>
<p>