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.
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.
Comments
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.
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.