3 ms·
This is my question as well. I don't write a lot of C or Rust code, so I'm curious when int -> ptr and ptr -> int conversions are actually needed in practice. T
by seo-speedwagon 5y ago
This is my question as well. I don't write a lot of C or Rust code, so I'm curious when int -> ptr and ptr -> int conversions are actually needed in practice. The only scenarios I can think of with my limited domain experience in are low-level things where you actually know the numeric addresses of certain important locations in memory. In which case, saying "yeah, that's a lower level in the weakenings tower" seems sensible.
- mh7 5y agoA classic example is when you're writing a custom allocator and need to align the address. Another is storing pointers in a hash table - you need to do arithmetic on the pointer bits to compute the hash.
- Gankra 5y agoI already designed several new convenience methods for making this kind of thing simple and the PR to rust-lang is already open :)