Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spec: document that Alignof, Offsetof, and Sizeof do not evaluate their arguments #12946

mdempsky opened this issue Oct 15, 2015 · 2 comments


Copy link

@mdempsky mdempsky commented Oct 15, 2015

At least in cmd/compile, unsafe.Alignof, unsafe.Offsetof, and unsafe.Sizeof do not evaluate their arguments:

Although unsurprising and consistent with C/C++, the Go spec doesn't mention this. It does say

Calls to Alignof, Offsetof, and Sizeof are compile-time constant expressions of type uintptr.

but I don't think that's necessarily mutually exclusive with evaluating the argument expression.

@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Oct 15, 2015
Copy link

@gopherbot gopherbot commented Oct 16, 2015

CL mentions this issue.

Copy link

@tzneal tzneal commented Aug 11, 2018

I like the current behavior, as it allows the following to work which lets you get sizes of arbitrary types given their names:


See, 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.