3 ms·
Related discussion at internals.rust-lang.org: https://internals.rust-lang.org/t/pointers-are-complicated-or-whats-in-a-byte/8045 https://internals.rust-lang.o
by cjcole 8y ago
Related discussion at internals.rust-lang.org:
https://internals.rust-lang.org/t/pointers-are-complicated-or-whats-in-a-byte/8045 https://internals.rust-lang.org/t/pointers-are-complicated-o...
"This summer, I will again work (amongst other things) on a “memory model” for Rust/MIR. However, before I can talk about the ideas I have for this year, I have to finally take the time and dispel the myth that “pointers are simple: they are just integers”. Both parts of this statement are false, at least in languages with unsafe features like Rust or C: Pointers are neither simple nor (just) integers.
I also want to define a piece of the memory model that has to be fixed before we can even talk about some of the more complex parts: Just what is the data that is stored in memory? It is organized in bytes, the minimal addressable unit and the smallest piece that can be accessed (at least on most platforms), but what are the possible values of a byte? Again, it turns out “it’s just an 8-bit integer” does not actually work as the answer."
Ralf Jung is a coauthor of the "What’s the difference between an integer and a pointer?" paper.
- simias 8y agoOkay I can agree with that but then there's no need to look for contrived examples, the C standard itself spells out a bunch of UB that arise from using pointers as "just integers". It's probably worth repeating, especially for people new to these languages, but it's not exactly breaking news. I guess I just expected something else when I started reading this article.