From: Robert Griesemer
int
-Call Argument type Result
+Call Argument type Result
-len(s) string type string length in bytes
- [n]T, *[n]T array length (== n)
- []T slice length
- map[K]T map length (number of defined keys)
- chan T number of elements queued in channel buffer
+len(s) string type string length in bytes
+ [n]T, *[n]T array length (== n)
+ []T slice length
+ map[K]T map length (number of defined keys)
+ chan T number of elements queued in channel buffer
-cap(s) [n]T, *[n]T array length (== n)
- []T slice capacity
- chan T channel buffer capacity
+cap(s) [n]T, *[n]T array length (== n)
+ []T slice capacity
+ chan T channel buffer capacity
@@ -4467,20 +4488,17 @@ The length and capacity of a nil slice, map, or channel are 0.
-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.
+The expression len(s) is constant if
+s is a string constant. The expressions len(s) and
+cap(s) are constants if the type of s is an array
+or pointer to an array and the expression s does not contain
+channel receives or
+function calls; in this case s is not evaluated.
+Otherwise, invocations of len and cap are not
+constant and s is evaluated.
+
Allocation
@@ -5169,5 +5187,8 @@ The following minimal alignment properties are guaranteed:
Implementation differences - TODO
- - Implementation does not honor the restriction on goto statements and targets (no intervening declarations).
+ - The restriction on
goto statements and targets (no intervening declarations) is not honored.
+ len(a) is only a constant if a is a (qualified) identifier denoting an array or pointer to an array.
+ nil maps are not treated like empty maps.
+ - Trying to send/receive from a
nil channel causes a run-time panic.