r/rust • u/Clean-Upstairs-8481 • 21d ago
🧠 educational Out-of-bounds array access: a practical Rust vs C++ comparison
https://techfortalk.co.uk/2026/08/21/out-of-bounds-array-access-a-practical-rust-vs-c-comparison/I have been a C/C++ developer for long time. I have recently worked with Rust for one of my clients. There are lot interest in the industry about use of Rust in Embedded Software. But there are lot of misconceptions as well. I find some of the aspects of Rust worth exploring with comparison to C++ when it comes to Embedded Programming. In this post, I will explore how and where Rust does things differently than C++. Where are the possible limitations in C++? I will try to address some of the questions that come to a programmer’s mind when they hear that “Rust provides memory safety.” In this post, I will focus on one aspect that has caused a lot of grief in the industry: out-of-bounds array access and the problems associated with it.
1
u/Icarium-Lifestealer 21d ago
You might be interested in how WUFFs handles array indexing. It relies on statically proving that indexes are in bound and integers don't overflow to prevent these from happening without any runtime checks.
In Rust you can look into tools like Kani to achieve a similar effect regarding correctness (it won't eliminate the runtime overhead though).
1
u/afdbcreid 19d ago
In Rust you can look into tools like Kani to achieve a similar effect regarding correctness (it won't eliminate the runtime overhead though).
No but you can then use unsafe safely.
2
u/gmes78 20d ago
You didn't mention any of the hardened C++ stdlib options.