Mixing safe and unsafe
Mixing safe and unsafe
Posted Oct 31, 2025 17:24 UTC (Fri) by epa (subscriber, #39769)In reply to: Mixing safe and unsafe by matthias
Parent article: Fil-C: A memory-safe C implementation
You make a good point, but the same applies to ordinary C code. In unchecked C you immediately have undefined behaviour if there are invalid pointers in a linked list. And so on. It's surely easier for the programmer to worry about all these nasty problems in just 5% of the code than in all of it.
You have to verify that the unsafe block is never called with violated invariants,I didn't quite understand this point. You do have to verify that -- but surely to do so it's enough to prove that all unsafe blocks in your program are behaving nicely? If the unsafe blocks are correct, then the other 95% of the code (the "safe" part) will not violate any invariants -- or at least if it does so, the program will blow up at run time as soon as it happens. (Fil-C does not claim to give you the same thorough compile-time checking as Rust.)
