4 ms·
assert() by itself is typically not the same as "defining an invariant". An invariant is an expression which should be true for the whole life-time of the block
by judofyr 6y ago
assert() by itself is typically not the same as "defining an invariant". An invariant is an expression which should be true for the whole life-time of the block/function/program/anything, but assert() only defines an assertion at a specific point.
- nimmer 6y agoPlus, assert() is commonly used for runtime checks, not static analysis.
- rurban 6y agoYou can use static_assert but compilers observe assert already. assume is another commonly used invariant.
- Someone 6y ago“An invariant is an expression which should be true for the whole life-time of the block/function/program/anything” It should hold at both entry and exit of a block, but practically always doesn’t for the entire block.