add thanks
[web.git] / ralf / _posts / 2018-07-24-pointers-and-bytes.md
index 61ecc14c8f2f5ccb52ffc80f4c6f863fc4e1ec4d..8338de4274e405b5a347cbf3973a9a44c06b3eeb 100644 (file)
@@ -1,6 +1,7 @@
 ---
 title: "Pointers Are Complicated, or: What's in a Byte?"
 categories: internship rust
+forum: https://internals.rust-lang.org/t/pointers-are-complicated-or-whats-in-a-byte/8045
 ---
 
 This summer, I am again [working on Rust full-time]({{ site.baseurl }}{% post_url 2018-07-11-research-assistant %}), and again I will work (amongst other things) on a "memory model" for Rust/MIR.
@@ -43,7 +44,7 @@ First of all, it is not allowed to perform pointer arithmetic (like `&x[i]` does
 Our program violates this rule: `x[i]` is outside of `x`, so this is undefined behavior.
 To be clear: Just the *computation* of `x_ptr` is already UB, we don't even get to the part where we want to *use* this pointer![^1]
 
-[^1]: It turns out that `y-x` is also undefined behavior because [one may only subtract pointers into the same allocation](https://timsong-cpp.github.io/cppwp/n4140/expr.add#6). However, we could use `i = ((size_t)y - (size_t)x)/sizeof(int)` to work around that.
+[^1]: It turns out that `i = y-x` is *also* undefined behavior because [one may only subtract pointers into the same allocation](https://timsong-cpp.github.io/cppwp/n4140/expr.add#6). However, we could use `i = ((size_t)y - (size_t)x)/sizeof(int)` to work around that.
 
 But we are not done yet: This rule has a special exception that we can exploit to our advantage.
 If the arithmetic ends up computing a pointer *just past* the end of an allocation, that computation is fine.
@@ -199,8 +200,12 @@ Using `Uninit` instead of an arbitrary bit pattern means miri can, in a single e
 
 ## Conclusion
 
-We have seen that pointers can be different even when they point to the same address, and that a byte is more than just a number in `0..256`.
+We have seen that pointers can be different even when they point to the same address, and that a byte is more than just a number in `0..256`.[^4]
 With this, I think we are ready to look at a first draft of my "2018 memory model" (working title ;) -- in the next post. :)
-<!-- If you have any questions, feel free to [ask in the forums]! -->
+
+Thanks to @rkruppe and @nagisa for help in finding arguments for why `Uninit` is needed.
+If you have any questions, feel free to [ask in the forums](https://internals.rust-lang.org/t/pointers-are-complicated-or-whats-in-a-byte/8045)!
+
+[^4]: And just to be clear, I am talking about a pointer or byte in the model of an optimized *programming language* here.  When modeling hardware, everything is different.
 
 #### Footnotes