-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: Sizeof isn't unsafe and could be elsewhere #5602
Comments
A program that uses If we do move these functions out of unsafe, they could become predeclared identifiers like |
It's already in reflect. It's just not as efficient. I suppose the compiler could recognize at least certain (simple) uses of reflect.Type.Size, though. |
A simpler solution would probably be for safe mode to only deny access to type unsafe.Pointer, not the entire package unsafe. |
People are confused by Sizeof. They think it's like C sizeof (although that might not be how they would describe it themselves). But it's really not, or at least not in a way that's simple to describe. It's hard to define it in a non-operational way. Just look at I think a better idea is to make it portable to ask the simple-to-answer questions, perhaps by constants in the reflect or runtime packages: SizeofInt, SizeofBool, etc. We'd leave out SizeofSlice and SizeofString and such because they are confusing. In other words, handle the safe (that is, simple and non-confusing) case safely, and leave the nastier cases in package unsafe. |
There doesn't seem to be a strong reason to implement this change. We can consider Rob's suggestion above ( |
The text was updated successfully, but these errors were encountered: