How arguments laid out at runtime?

Hi gophers,
I’m learning to read panic messages. As far as I know, a string is passed in as a pointer to data and a length, a struct is spread out. However when I testing around with the following code, there’s a 0x1 at the end of func hey. When I give it a filed z and value, it changes to that value. What does it mean and why is this?
playground

package main

import (
	"fmt"
	"unsafe"
)

type Nil int

func (n *Nil) hello() {
	fmt.Println(*n)
	panic("no no no")
}

type A struct {
	x string
	y *Nil
	//z int
}

func main() {
	var a A
	a.x = "string"
	none := Nil(2)
	a.y = &none
	//a.z = 3
	fmt.Println(unsafe.Sizeof(a))
	hey(a)
}

func hey(a A) {
	a.y.hello()

}
12
2
panic: no no no

goroutine 1 [running]:
main.(*Nil).hello(...)
	/tmp/sandbox662940585/prog.go:12
main.hey(0x115e1c, 0x6, 0x41a784, 0x1)
	/tmp/sandbox662940585/prog.go:32 +0xc0
main.main()
	/tmp/sandbox662940585/prog.go:28 +0xa0

Program exited: status 2.

Most likely to ensure stack alignment.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.