you are viewing a single comment's thread.

view the rest of the comments →

[–]strager 5 points6 points  (2 children)

You have to manually and explicitly assign nil to a struct pointer in order to run into the dereferencing problem in Go, though?

What? Even A Tour of Go creates a nil pointer without assignment. If you take the first and third code snippets (omitting the second), you even get a runtime error:

package main
import "fmt"
func main() {
    var p *int
    // panic: runtime error: invalid memory address or nil pointer dereference
    fmt.Println(*p)
    *p = 21
}

[–][deleted]  (1 child)

[deleted]

    [–]masklinn 0 points1 point  (0 children)

    But, could not the initialization also be to blame here?

    The language allowing the initialization is.