assert() says: this ought to hold when I do testing
assume() says: I have proven this to hold

Just as another example of how these two are different:

You might want to assert() that you have enough headroom in a statically allocated buffer when testing. Say you assert that the buffer is never more than 50% full for normal loads. You obviously don't want the -release build to make such an assumption!

So the content of an assert() is in this regard different from a prove(). It can sometimes be desirable to put too strong constraints on the program when testing, then relax it on release to get that extra headroom for "odd situations".

You can probably make the same argument for tolerances in computations that are approximate/randomized/iterative. Testing for a tight tolerance does not mean that you want the optimizer to assume that the tolerance is always within that bound. You want some extra headroom in release to be sure that it behaves correctly under more difficult circumstances.

Reply via email to