This question already has an answer here:
I have seen some Go functions defined like this:
type poly struct {
coeffs [256]uint16
}
func (p *poly) reset() {
for i := range p.coeffs {
p.coeffs[i] = 0
}
}
Which you can later call as:
var p poly
p.reset()
I haven't seen this in other programming languages that I know. What's the purpose of p *poly
in the reset function? It seems to be like a function parameter but written before the function name. Any clarification for it?
</div>
It means that reset()
is a method on *poly
. This is very basic Go; you really need to start with the Go tour. Trying to read Go without a basic understanding of its syntax is going to be very confusing.