Seminar 7 (CPP)
C/CPP build.
Tasks
Task 0
Use macros to implement custom casserts:
int foo() { return 1; }
int y = 2;
int main() {
assert(foo() > y);
}
Output must be:
$ ./a.out
a.out: a.cc:7: int main(): Assertion `foo() > y' failed.
Task 1
Update the assert macro so that it has two options:
-
assert(EXPR)— has the same behaviour -
assert(EXPR, MSG)— add a custom messageMSG
When the sources are compiled with -DNDEBUG, all asserts must be ignored, e.g. the code below must not print anything:
int foo() { std::cout << "Hi"; return 1; }
int y = 2;
int main() {
assert(foo() > y);
}