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
unsafe.Sizeof and unsafe.Alignof on numeric constants #799
Labels
Comments
"A constant may be given a type explicitly by a constant declaration or conversion, or implicitly when used in a variable declaration or an assignment or as an operand in an expression. ... For instance, 3.0 can be given any integer or any floating-point type, while 2147483648.0 (equal to 1<<31) can be given the types float32, float64, or uint32 but not int32 or string." Constants, The Go Programming Language Specification. http://golang.org/doc/go_spec.html#Constants Aren't you are asking for the size of and alignment of an untyped constant, which are undefined? The constant 3 can be given any integer or any floating-point type. Give it a type e.g. float(3), int64(3), etc. More meaningful error reporting would be nice. "Sizeof returns the size in bytes occupied by the value v. The size is that of the "top level" of the value only. For instance, if v is a slice, it returns the size of the slice descriptor, not the size of the memory referenced by the slice." func Sizeof. http://golang.org/pkg/unsafe/#Sizeof String literals are typed, they are strings. Aren't the size of and alignment of a string returned by unsafe actually the size of and alignment of the string descriptor? |
The size of an untyped constant is undefined, I agree. If no one does anything about this part, I can't complain too much. The internal compiler error definitely seems like a bug to me, though. Also note that string literals are not typed. I can say: type S string var s S = "A string" If string literals were typed, that would fail to compile. I think it's inconsistent that I get a somewhat reasonable value for the size of a string literal, but not for a numeric literal. |
Owner changed to r...@golang.org. Status changed to Accepted. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The text was updated successfully, but these errors were encountered: