Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>The Google Go docs <a href="http://golang.org/doc/go_tutorial.html#tmp_94" rel="nofollow noreferrer">state the following about passing arrays</a> - they say you usually want to pass a slice (instead of a pointer?):</strong></p> <h2>Updated:</h2> <p>As indicated by @Chickencha's comment, array slices are references which is why they are efficient for passing. Therefore likely you will want to use the slice mechanism instead of "raw" pointers. </p> <p>From <strong>Google Effective Go doc</strong> <a href="http://golang.org/doc/effective_go.html#slices" rel="nofollow noreferrer">http://golang.org/doc/effective_go.html#slices</a></p> <blockquote> <p><em>Slices are reference types,</em></p> </blockquote> <hr> <h2>Original</h2> <p>It's under the heading</p> <p><strong>An Interlude about Types</strong> </p> <blockquote> <p>[...snip...] When passing an array to a function, you almost always want to declare the formal parameter to be a slice. When you call the function, take the address of the array and Go will create (efficiently) a slice reference and pass that.</p> </blockquote> <p><em>Editor's note: This is no longer the case</em></p> <p>Using slices one can write this function (from sum.go):</p> <pre><code>09 func sum(a []int) int { // returns an int 10 s := 0 11 for i := 0; i &lt; len(a); i++ { 12 s += a[i] 13 } 14 return s 15 } </code></pre> <p>and invoke it like this:</p> <pre><code>19 s := sum(&amp;[3]int{1,2,3}) // a slice of the array is passed to sum </code></pre> <hr> <p>Maybe pass the whole array as a slice instead. Google indicates Go deals efficiently with slices. This is an alternate answer to the question but maybe it's a better way.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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