On Tue, Dec 25, 2018 at 10:13 PM <[email protected]> wrote:
>
> I notice in the source comiler go initialize a Node n use a temp x, why the 
> variable n is initialized like this?
>
> why just initilize the n like below?
> n = new(Node)
> n.Func = new(Func)
>
>
>
> the source from File: src/cmd/compile/internal/gc/subr.go
> func nodl(pos src.XPos, op Op, nleft, nright *Node) *Node {
>    var n *Node
>    switch op {
>    case OCLOSURE, ODCLFUNC:
>        var x struct {
>            Node
>            Func
>        }
>        n = &x.Node
>        n.Func = &x.Func
>    case ONAME:
>        Fatalf("use newname instead")
>    case OLABEL, OPACK:
>        var x struct {
>            Node
>            Name
>        }
>        n = &x.Node
>        n.Name = &x.Name
>    default:
>        n = new(Node)
>    }
>    n.Op = op
>    n.Left = nleft
>    n.Right = nright
>    n.Pos = pos
>    n.Xoffset = BADWIDTH
>    n.Orig = n
>    return n
> }
>
> Anyone can explain this?


See https://golang.org/cl/36022.

Ian

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to