Mixing safe and unsafe
Mixing safe and unsafe
Posted Oct 29, 2025 6:18 UTC (Wed) by epa (subscriber, #39769)Parent article: Fil-C: A memory-safe C implementation
This sounds more practical than previous safe C implementations (such as the c-semantics interpreter, which must be hundreds of times slower than compiled code). Can you mix it with compiled, optimized object code in the same program? I might want to run 95% of my code with full safety checks but in a few hot spots declare an “unsafe” block which will run close to native speed by eliminating most checks. Of course, the burden is on me to ensure those blocks are safe and don’t have any undefined behaviour.
The unsafe-compiled code wouldn’t be exactly the same as you get from plain clang, as the memory layout is different, and it might be a bit slower because of that, but it could do without checks of pointer capability checking and, perhaps, other checks like overflow and array bounds. The rest of the program must assume that the unsafe code is correct.
