Mixing safe and unsafe
Mixing safe and unsafe
Posted Oct 29, 2025 14:13 UTC (Wed) by matthias (subscriber, #94967)In reply to: Mixing safe and unsafe by tialaramex
Parent article: Fil-C: A memory-safe C implementation
The pointer can point to things, it can point one past the end of an array (used in the slice iterator), or it can just contain garbage and must never be dereferenced.
The main difference wrt. raw pointers between the languages is, that in rust you have to use unsafe if you want to dereference a pointer. Rust has adopted the C++ memory model, i.e., the rules regarding atomic accesses and how they order wrt. raw pointer accesses. They actually refer to the C++ semantics for this. Rust does not yet have pointer provence, but this is in the discussion and might end up being also quite similar to C. All in all, raw pointers work very much the same.
Of course, this is a totally difference game when it comes to references where the compiler enforces strict invariants regarding validity.
(*) Probably more than three categories, e.g. pointers to uninitialized memory, where you are only allowed to write but not to read. Null pointers are also somewhat special, as you are allowed to compare them.
