ch3-Assert debugging macro in C/C++

Chapter_3     Exercise_3-31 ComplicatedDefinitions     Exercise_3-32







Assert     TCP1, p. 212  (assert.c,  Assert.cpp)




assert.c         download


//#define NDEBUG
#include <assert.h> // for assert() debug macro

int main()
{
int i = 100;

assert(i != 100);

return 0;
}
/*
gcc assert.c -o assert
./assert
assert: assert.c:8: main: Assertion `i != 100' failed.
Aborted (core dumped)

gcc assert.c -o assert -D NDEBUG
./assert
*/





Note:  See also ch2-assert on the blog Advanced_Linux_Programming, Chapter_2, Sec. 2.2.











Assert.cpp         download


//#define NDEBUG
#include <cassert> // for assert() debug macro

int main()
{
int i = 100;

assert(i != 100);

return 0;
}
/*
g++ Assert.cpp -o Assert
./Assert
Assert: Assert.cpp:8: int main(): Assertion `i != 100' failed.
Aborted (core dumped)

g++ Assert.cpp -o Assert -D NDEBUG
./Assert
*/









Chapter_3     Exercise_3-31 BACK_TO_TOP ComplicatedDefinitions     Exercise_3-32



Comments

Popular posts from this blog

Contents