if and case statements make understanding tricker.
<cassert> for C++.
assert() macro.
assert() Macroassert() macro takes a single expression as an argument.
$ cat t.cc
#include <cassert>
int main() {
const int two = 2;
assert(two < 1);
}
$ g++ -o t t.cc
$ ./t
Assertion failed: two < 1, file t.cc, line 5
Abort(coredump)
$
std::string inp; std::cin >> inp;if (inp[0] == '#') { ... }
std::string inp;
std::cin >> inp;
assert(inp.size() > 0);
if (inp[0] == '#') { ... }
// Input is never empty. assert(inp.size() > 0);
NDEBUG.
g++ -DNDEBUG ...
or in your code (before the <cassert>).
#define NDEBUG #include <cassert>
assert macros.
Wrong:
// The file must exist, I just created it.assert(ifs.open(fname));
Right:
// The file must exist, I just created it. const bool ok = ifs.open(fname); assert(ok);
This page last modified on 31 January 2003.