-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
proposal: Go 2: integer array <-> integer type conversion #37658
Comments
What should the endianness of the converted value be? |
For language change proposals, please fill out the template at https://go.googlesource.com/proposal/+/refs/heads/master/go2-language-changes.md . When you are done, please reply to the issue with Thanks! |
This can be done now using encoding/binary. The compiler generates very good code for these routines, equivalent (I strongly suspect) to what a built-in conversion would do. It would be good to explain why encoding/binary is insufficient here. |
@gopherbot please remove label WaitingForInfo |
Whatever the target's endianness is at compile time. It should behave like an |
This was discussed indirectly at #35398 |
Ok, so because of endianness:
right? We cant just think like How about we make it well-defined. We define the conversion such that Josh, encoding/binary doesn't seem very convenient in terms of intuition & readability. It looks more suitable for run-time conversion, whereas this is a compile time feature. Though I am sure the compiler can be made to output efficient assembly for it. |
I’m not sure I understand the distinction here. I believe that are functionally identical. Can you explain more? |
sorry yes, runtime/compile time distinction is not accurate since we need byte swap operations on some platforms to get the consistency. |
We aren't going to intentionally make simple programs (that don't use unsafe) generate different results on different systems. If we adopt little endian conversions as suggested above, what is the advantage of allowing these conversions? It's always possible to write these conversions out directly. Does this really come up often enough to add a somewhat obscure conversion? |
I guess you are right in that:
|
Integer types are convertable to each other. I propose to extend it to arrays:
This will allow to see:
without
unsafe.Pointer
tricks.The text was updated successfully, but these errors were encountered: