I'm a beginner in learning Go, and I'm puzzled by the following two questions:
First:
type S struct{
a func()
b func(i int, j float32, k string)
c *func()
}
func main(){
s := S{c: &func(){}} // Error: Cannot take the address of `func(){}`
}
In this struct, c *func()
is valid, but how can I assigned to it
?
Second:
As I know, functions are first class citizens, so I can pass function as a parameter to another function/method, also I can declare a function variable, so, how does a function value works
, does it's actually a function pointer?
I read some articles about alignment and padding, I know a interface value take up 16 bytes(64-bit system) because a interface value is composed of data pointer and type pointer, what about function value
? I use unsafe.Sizeof(funcValue)
and it returns 8, so I guess it's actually a function pointer. Is there any way to prove it(right or wrong)?