3 ms·
> If after the above I created an array like so `char str[n]` and then assigned such that it pointed to the same region of memory that malloc() returned, then w
by SkiFire13 2y ago
> If after the above I created an array like so `char str[n]` and then assigned such that it pointed to the same region of memory that malloc() returned, then would the provenance of both pointer be equal?
I don't think you can perform such assignment.
> Also, in Rust why are pointer to integer casts allowed at all if they lose provenance?
Sometimes you want the numeric address to perform some arithmetic/bitwise operation on it (e.g. for tagged pointers)
> Also, why exactly is one past end of bounds a valid pointer you can calculate?
Because it's increadibly useful for iterating. It is also used for representing an empty tail slice. It's something inherited from C/C++ and likely won't go away.
> Also, it seems like you cannot just create a random pointer to an unallocated address, not just that you can’t write to it. Is that correct?
You can create such pointer, it just won't be valid.
> Lastly, is provenance just a fancy way of saying metadata? Is there a reason something like “pointer metadata” or “object metadata” wasn’t used?
It's not metadata that exists at runtime. It only exist at compile time to allow certain common optimizations.