Hacker News new | past | comments | ask | show | jobs | submit login

> How do self references work when the struct is moved, given that they're pointers?

Are all references necessarily (global) pointers? Couldn't self references be offsets?




Yes, they are necessarily global pointers. If a self reference is an offset, what happens when you take its address (and pass that somewhere else that doesn't know where it came from)?

Now every "reference to a reference" (and similar things) can dynamically be a global pointer or a relative one, with no way to tell how to use it.


Am I necessarily always allowed to convert a reference to a numeric address?


Yes, it's safe to cast a reference to a raw pointer and a raw pointer to an address.

It might have been nicer in some ways if the language had restricted that a bit more up front, but it would probably have taken some design work to do that while still supporting a lot of the low-level stuff people need to do.


An internal reference could only be cast to a relative memory offset. It’s not a global memory address in disguise like a normal reference. So the same casting rules wouldn't apply.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: