Hacker News new | ask | show | jobs
by sagacity 570 days ago
One point I didn't see mentioned that asserts can be used by the compiler to enable certain optimisations.

For instance, if you assert that an incoming index into a function is within the bounds of a vector, then during the rest of the function the compiler can elide any bounds checking.

1 comments

What C compiler would add bounds checks?
That was just an example. In Rust bounds checks can be eliminated in this way, but I'm sure there are similar optimisation opportunities in C code as well.