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

proposal: unsafe: make the Pointer type declaration consistent with the ones in the "builtin" package #36282

Closed
go101 opened this issue Dec 26, 2019 · 3 comments

Comments

@go101
Copy link

go101 commented Dec 26, 2019

In the current unsafe code, the Pointer is declared as

type ArbitraryType int
type Pointer *ArbitraryType

which might be good in some aspects, but it is also bad in some other aspects:

  1. it is not consistent with the type int int style in the builtin package.
  2. it leans to make people think the underlying type of Pointer is not itself.
  3. it brings some troubles for implementing some code analysis tools.

So, I propose that using the following way to declare the Pointer type:

type Pointer Pointer

and we can mention the Pointer type is a builtin type and acts as a *ArbitraryType in its document.

@go101 go101 changed the title propsoal: unsafe: make the Pointer type declaration consistent with the ones in "builtin" package proposal: unsafe: make the Pointer type declaration consistent with the ones in the "builtin" package Dec 26, 2019
@gopherbot gopherbot added this to the Proposal milestone Dec 26, 2019
@robpike
Copy link
Contributor

robpike commented Dec 26, 2019

That won't parse. it's not a valid declaration of Pointer. The trick works in the builtin package because when we say

type bool bool

The bool on the right is a name that has already been declared.

@ianlancetaylor
Copy link
Contributor

I think it's quite reasonable to say that the underlying type of int is int, but that the underlying of unsafe.Pointer is not unsafe.Pointer. The underlying type of unsafe.Pointer is a pointer type; we just don't have a way to write what it points to, which is why the package says ArbitraryType.

@go101
Copy link
Author

go101 commented Dec 27, 2019

OK, I will close this issue.

@go101 go101 closed this as completed Dec 27, 2019
@golang golang locked and limited conversation to collaborators Dec 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants