by Someone · 4y ago · 0 comments
So, currently, there is no way to force memory layout, other than, as https://github.com/golang/go/issues/10014#issuecomment-26346... says
“defining the type using [n]byte and modifying the fields using the encoding/binary package. On many processors the performance will be approximately the same.”
Seems unsatisfactory to me.
The spec doesn't, but the actual compiler implementation does. If the compiler is not allowed to re-order fields, they remain in the order the programmer specified in the code. That's why the fix in the article works in the first place.
Technically you could say it wouldn’t even be a breaking change if a compiler update changed that (practically people would have reason to be angry if they slipped something like that in without creating a major version and adding warning flags to the release notes)