From f4429181df814edefb122f7c2a4a4e093d52ff71 Mon Sep 17 00:00:00 2001
From: Russ Cox unsafe.Sizeof
-and cap
or len
applied to an array,
-len
applied to a string constant,
+the result value of some built-in functions such as
+unsafe.Sizeof
applied to any value,
+cap
or len
applied to
+some expressions,
real
and imag
applied to a complex constant
and cmplx
applied to numeric constants.
The boolean truth values are represented by the predeclared constants
@@ -754,8 +755,7 @@ ElementType = Type .
The length is part of the array's type and must be a
constant expression that evaluates to a non-negative
integer value. The length of array a
can be discovered
-using the built-in function len(a)
, which is a
-compile-time constant. The elements can be indexed by integer
+using the built-in function len(a)
. The elements can be indexed by integer
indices 0 through the len(a)-1
(§Indexes).
Array types are always one-dimensional but may be composed to form
multi-dimensional types.
@@ -805,7 +805,7 @@ a slice of length up to that capacity can be created by `slicing' a new
one from the original slice (§Slices).
The capacity of a slice a
can be discovered using the
built-in function cap(a)
and the relationship between
-len()
and cap()
is:
+len(a)
and cap(a)
is:
@@ -4358,12 +4358,12 @@ The implementation guarantees that the result always fits into an int
@@ -4378,6 +4378,20 @@ At any time the following relationship holds:
0 <= len(s) <= cap(s)
+
+The expression
+len(s)
is a
+constant if s
is a string constant.
+The expressions
+len(s)
and
+cap(s)
are
+constants if s
is an (optionally parenthesized)
+identifier or
+qualified identifier
+denoting an array or pointer to array.
+Otherwise invocations of len
and cap
are not
+constant.
+