The purpose of this quiz is to give you a chance to focus your knowledge of simple debugging with assert in C++.
The assert macro from our C heritage will allow you to test for certain Boolean conditions at run-time and crash the program should they not be met. This macro is located in the library header cassert.
This is crashing is somewhat handy during the debugging stage of development but not so good during production phase. To avoid crashes during a production run, we just need the macro NDEBUG to turn all the Boolean tests off all at once. This macro has no specific value and just needs to be created with #define.
This macro is most often used to test a function's parameters/arguments against boundary/domain concerns. Just place the macro with your Boolean condition testing your function's parameters in the parentheses and your program will crash when provided parameters don't pass the test. The message will tell the function name and the test that failed, typically.
TRUE ✓ | FALSE ✗ | The trouble with this macro is that it has no information about where the function that experienced the issue was called from. | ||
---|---|---|---|---|
TRUE ✗ | FALSE ✓ | Thus, when you crash, you know what function called with bad parameters, but not what function was executing! | ||
TRUE ✓ | FALSE ✗ | Tracking down the right call point can be quite tricky and most likely will involve narrowing the search with bounding cerr displays. |