I'm experiencing a weird problem with my program and finally nail it down 
to what exactly went wrong, so that I can write a minimum program to 
duplicate it. See the following program:

package main

import (

type Vertex struct {
 X int
 Y int

func main() {
 vs := []Vertex{
 Vertex{1, 2}, // has type Vertex
 Vertex{X: 3}, // Y:0 is implicit
 Vertex{},     // X:0 and Y:0

 fmt.Printf("Vertex Slice %+v\n", vs)
 var vp *Vertex = nil
 for _, v := range vs {
 if v.X == 3 {
 vp = &v
 fmt.Printf("Found: %+v\n", vp)


I was expecting that the found Vertex is "v.X == 3", however the result is 

- what exactly is causing the problem?
- how to fix it so that I got what I was looking for? 

Again, the snip is at


You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 

Reply via email to