by randomNumber7 · 10mo ago · 0 comments
UnsafeMutablePointer, UnsafePointer, UnsafeMutableBufferPointer, UnsafeBufferPointer, UnsafeMutableRawPointer, UnsafeRawPointer, UnsafeMutableRawBufferPointer, UnsafeRawBufferPointer
?? This is comical and the only reason to make it this clunky is because "unsafe is bad" and you don't want people to use it.
- Mutable or not
- Typed or Raw
- Single object, or Buffer
Given one kind of pointer, you can convert to any other kind of pointer, but you are responsible for knowing if it’s safe to do.
The API is not super intuitive, but I can see how it makes it more clear what you are doing in your code.
Is it a pointer to raw memory or a pointer to a type? Does it have a known size? Should it be allowed to be changed?
These are all questions you have to answer in C but cannot without annotations or documentation. Languages with more expressive type systems need to map that ambiguity to something.