Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Arrays may be indexed by any integer type.</p> <p>The <a href="http://golang.org/ref/spec#Array_types" rel="nofollow">Array types</a> section of the <a href="http://golang.org/ref/spec" rel="nofollow">Go Programming Language Specification</a> says that in an array type definition,</p> <blockquote> <p>The length is part of the array's type and must be a constant expression that evaluates to a non-negative integer value.</p> </blockquote> <p>In an <a href="http://golang.org/ref/spec#Indexes" rel="nofollow">index expression</a> such as <code>a[x]</code>:</p> <blockquote> <p><code>x</code> must be an integer value and <code>0 &lt;= x &lt; len(a)</code></p> </blockquote> <p>But there is a limitation on the <em>magnitude</em> of an index; the description of <a href="http://golang.org/ref/spec#Length_and_capacity" rel="nofollow">Length and capacity</a> says:</p> <blockquote> <p>The built-in functions <code>len</code> and <code>cap</code> take arguments of various types and return a result of type <code>int</code>. The implementation guarantees that the result always fits into an <code>int</code>.</p> </blockquote> <p>So the declared size of an array, or the index in an index expression, can be of any <a href="http://golang.org/ref/spec#Numeric_types" rel="nofollow">integer type</a> (<code>int</code>, <code>uint</code>, <code>uintptr</code>, <code>int8</code>, <code>int16</code>, <code>int32</code>, <code>int64</code>, <code>uint8</code>, <code>uint16</code>, <code>uint32</code>, <code>uint64</code>), but it must be non-negative and within the range of type <code>int</code> (which is the same size as either <code>int32</code> or <code>int64</code> -- though it's a distinct type from either).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload