Skip to content

Instantly share code, notes, and snippets.

@farhaven
Created March 15, 2015 17:33
Show Gist options
  • Save farhaven/a97645d4dd8bdf1c7f8d to your computer and use it in GitHub Desktop.
Save farhaven/a97645d4dd8bdf1c7f8d to your computer and use it in GitHub Desktop.
package main
import (
"log"
)
func a() []*int {
foo := make([]*int, 10)
for i, v := range foo {
log.Printf(`%v`, v)
x := i
foo[i] = &x
}
return foo
}
func b(foo []*int) {
for _, v := range foo {
log.Printf(`%v == %d`, v, *v)
}
}
func main() {
foo := a()
b(foo)
}
@RonjaPonja
Copy link

Easier checking if slice field has not been set by checking for nil instead of the datatypes default value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment