Bjarne Stroustrup’s Plan for Bringing Safety to C++ (The New Stack)
Bjarne Stroustrup’s Plan for Bringing Safety to C++ (The New Stack)
Posted Nov 2, 2023 17:05 UTC (Thu) by ojeda (subscriber, #143370)In reply to: Bjarne Stroustrup’s Plan for Bringing Safety to C++ (The New Stack) by adobriyan
Parent article: Bjarne Stroustrup’s Plan for Bringing Safety to C++ (The New Stack)
From your comment, I think you misunderstand what "safe" means in Rust.
It does not mean "the lines do not have UB because I checked" (like you do in your comment). It is the other way around -- that would be "unsafe" Rust.
In C, essentially any non-trivial line may contain UB. That is why they are "unsafe" in Rust terms, and why the statement about `wc -l` is quite close to reality.
Posted Nov 2, 2023 17:29 UTC (Thu)
by adobriyan (subscriber, #30858)
[Link] (1 responses)
"may contain" doesn't mean "contains". This fixation on UB is partially misguided.
> That is why they are "unsafe" in Rust terms, and why the statement about `wc -l` is quite close to reality.
C/C++ static checkers/compilers don't require to mark code with "safe" or "unsafe" and don't mark code themselves ex post facto.
I'm writing toy C compiler at the moment:
It is easy to verify for a human at high level (and sanitizers confirm) that there are no leaks and
Posted Nov 2, 2023 17:42 UTC (Thu)
by mb (subscriber, #50428)
[Link]
Yep. And that is what Rust calls "unsafe code, manually checked".
Get it now?
Bjarne Stroustrup’s Plan for Bringing Safety to C++ (The New Stack)
Rustc requires unsafe marks thus creating the illusion that close to 100% of C/C++ code is unsafe.
* C expressions are allocated from stable container,
* expressions form AST with pointers pointing to other expressions,
* pointers to expressions are never freed,
* references and other form of pointers aren't used,
* stable container is globally destructed when program exists (which is waste of cycles but this is for later).
there are no bugs with pointer management despite having a awful lots of pointers.
Bjarne Stroustrup’s Plan for Bringing Safety to C++ (The New Stack)
>there are no bugs with pointer management despite having a awful lots of pointers.
Safe code would be, if the compiler itself could prove that without human intervention.