4 ms·
assert() is a macro that will print an error message and abort the program if its argument doesn't evaluate to true. assert() is usually used in debug builds t
by KerrickStaley 11y ago
assert() is a macro that will print an error message and abort the program if its argument doesn't evaluate to true.
assert() is usually used in debug builds to verify internal invariants of the code: "if this is false, something has gone horribly, terribly wrong; we've gone crazy and we should abort to avoid further hurting ourselves or others". It shouldn't be used to verify that user input is well-formed, since this happens under normal circumstances.
- RickHull 11y agoFurthermore, assert is specifically intended to catch internal logic bugs which would still be present even after user input validation. i.e. logic bugs which are invariant upon user input