Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
spec: document that Alignof, Offsetof, and Sizeof do not evaluate their arguments #12946
At least in cmd/compile, unsafe.Alignof, unsafe.Offsetof, and unsafe.Sizeof do not evaluate their arguments: http://play.golang.org/p/4QE3mVrFaS
Although unsurprising and consistent with C/C++, the Go spec doesn't mention this. It does say
but I don't think that's necessarily mutually exclusive with evaluating the argument expression.
I like the current behavior, as it allows the following to work which lets you get sizes of arbitrary types given their names:
See https://play.golang.org/p/MeFfDzoGpxo, my reading of "compile-time constant expressions of" implied that is wouldn't evaluate the expression, leading me to the above construct. I'm using this in some generated code now.