Created
March 15, 2015 17:33
-
-
Save farhaven/a97645d4dd8bdf1c7f8d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Easier checking if slice field has not been set by checking for nil instead of the datatypes default value.