4 ms·
I personally always turned them on. Unlike with C arrays for example (which lose track of their length) Pascal keeps it around so the cost of a bounds-check is
by sirwhinesalot 3y ago
I personally always turned them on. Unlike with C arrays for example (which lose track of their length) Pascal keeps it around so the cost of a bounds-check is exactly what one would expect.
Perhaps I'm wrong regarding the culture of Pascal users though, only speaking for myself as someone who mostly coded in Delphi for fun.
Most C++ implementations provide an option to turn on bounds checks for operator [] in various container types but this actually against the standard, and std::span doesn't even have .at() standardized yet despite the implementation amounting to an if and a call to operator [].
So safety in C++ is very hit and miss. All the necessary tools are there but the standard is lousy as all heck. Like I argue in my blog, it's an attitude problem.
Don't use raw pointers/pointer arithmetic. Only use bounds checked operations even if you're 100% sure you got the bounds right (if it's that obvious the compiler will remove the check too). Don't store references anywhere, they should be ephemeral. Use std::unique_ptr and std::shared_ptr as appropriate, they are your friends. Don't use unsafe casts/untagged unions. etc.
It's not hard to have a linter check most of this. It's a matter of doing it.