News for hackers. Stuff that matters.
Re:Does Rust's array bounds checking affect performance (2017)? by labawi on Monday July 12, 2021 @11:23AM (#27811200)
If you want it safe, then the C++ version should also add a (single) length check. To fix rust's multiple points of failure, move the check to the top, by add something like 'let length_check = slice[5]', moving the 'slice[5]=5' to the top (or something nicer, don't know rust), and you will get only a single point of failure and a single check, same as safe C++ with matching API.

If you want to have 0 runtime checks, like the C++ example, you can

1) make it unsafe and actively dangerous, like the C++ version

2) change the API so minimum length is guaranteed (probably possible in rust, harder in C++)

3) have the function private/inline where sufficient length is known/can be deduced and the check will be omitted

Re:Does Rust's array bounds checking affect performance (2017)? by expnkx on Monday July 12, 2021 @04:57PM (#27815040)
If you want safety. you can just use _GLIBCXX_ASSERTIONS https://godbolt.org/z/eThdeW3Mv

It gives you all bounds checking you need.

In fact, a lot of Linux distributions (like Fedora) built all packages with _GLIBCXX_ASSERTIONS by default.