You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A Pointer is a pointer type but a Pointer value may not be dereferenced. Any pointer or value of core typeuintptr can be converted to a type of core type Pointer and vice versa. The effect of converting between Pointer and uintptr is implementation-defined.
Notably, while this does specify that conversion between unsafe.Pointer and uintptr is implementation-defined, it doesn't contain the same caveat for conversion between unsafe.Pointer and other pointers (like *int in the example above). So the spec does not give any way to reason about the behavior of the above program - not even that it is implementation defined.
The unsafe.Pointer rules do of course rule that program out, so the implementation-defined rules do allow us to reason about the program. But, technically speaking, we are not giving it purview to do that.
I would propose to change "The effect of converting between Pointer and uintptr is implementation-defined" to "The effect of such conversions is implementation-defined".
The text was updated successfully, but these errors were encountered:
@Merovius We probably were (implicitly) assuming that since an unsafe.Pointer is a pointer type, any conversion between pointer types only changes the types but doesn't really "do" anything at runtime - which is of course what happens but we (probably) don't want to write that down, yet we need to write something about it. I think your suggestion seems fine, thanks.
Based on a golang-nuts thread.
Consider this program:
The spec says about
unsafe.Pointer
:Notably, while this does specify that conversion between
unsafe.Pointer
anduintptr
is implementation-defined, it doesn't contain the same caveat for conversion betweenunsafe.Pointer
and other pointers (like*int
in the example above). So the spec does not give any way to reason about the behavior of the above program - not even that it is implementation defined.The
unsafe.Pointer
rules do of course rule that program out, so the implementation-defined rules do allow us to reason about the program. But, technically speaking, we are not giving it purview to do that.I would propose to change "The effect of converting between Pointer and uintptr is implementation-defined" to "The effect of such conversions is implementation-defined".
The text was updated successfully, but these errors were encountered: