This are my notes in the fields of computer science and technology. Everything is written with ABSOLUTE NO WARRANTY of fitness for any purpose. Of course, feel free to comment anything.

Thursday, April 16, 2009

assert.h

Assertions: you express your expectations in a certain position of the code, and this way you avoid bugs that would otherwise very difficult to trace.

In C use the standard library macro assert. You must #include <assert.h>, then you assert(expression); in the code, and if the expression is evaluating to 0 / false, the program aborts with an error msg printed on sterr that tells you which assertion fails and where it is (file/line).

It is also possible to turn assertions off, adding a #define NDEBUG before the #include <assert.h>.

No comments:

About Me

My photo
Hamburg, Hamburg, Germany
Former molecular biologist and web developer (Rails) and currently research scientist in bioinformatics.