by koakuma-chan · 1y ago · 0 comments
I admit there is many great products that are written in C that aren’t going anywhere any time soon, notably SQLite, but there is no reason to write new software in C or C++.
Personally, I'd use both Rust and C with equivalent code. The Rust types and borrow checker give some extra assurance that C might not have. The C tooling gives extra assurance Rust doesn't have. Win, win. If I want, I can also do a certified compile or cross-compile of the Rust-equivalent, C code.
https://www.absint.com/astree/index.htm
By the way, C has a formally verified C compiler:
On Astree, I couldn't believe it supported all language constructs. I found this on your link:
"and is subject to the same restrictions as Astrée for C.
The high-level abstraction features and template library of C++ facilitate the design of very complex and dynamic software. Extensive use of these features may violate the established principles of safety-critical embedded software development and lead to unsatisfactory analysis times and results. The Astrée manual gives recommendations on the use of C++ features to ensure that the code can be well analyzed. For less constrained (less critical) C++ code, we recommend using the standalone RuleChecker."
So, it still does require a language subset that reduces complexity to benefit from the full analysis. They have greatly expanded what errors they catch since I first read about them. So, thanks for the link.
```rust
#[kani::proof]
fn main() {
let mut array: [i32; 10] = kani::any();
array.sort_unstable();
let index: usize = kani::any_where(|i| *i > 0 && *i < array.len());
assert!(array[index] >= array[index - 1]);
}
```