Mixing safe and unsafe
Mixing safe and unsafe
Posted Oct 31, 2025 18:27 UTC (Fri) by matthias (subscriber, #94967)In reply to: Mixing safe and unsafe by epa
Parent article: Fil-C: A memory-safe C implementation
This is the way rust works, but not how Fil-C works. Fil-C checks the pointers when they are used. It does not check at compile time (that is what rust does with references) and it cannot check when they are constructed. A pointer can alias with an integer type. So you can write any value into the pointer and Fil-C will not complain. It will only complain when you try to use the pointer and the metadata is incorrect. If the first use of an invalid pointer is in the unsafe code and you have turned off the runtime checks in this part of the code then you have UB.
Once you turn off the runtime checks in any part of the code, you have to verify all code for correctness that touches the same memory as the unsafe code.
