## Thursday, April 28, 2005

### Assert Yourself

Well, assertiveness is a nice quality to have. It's a virtue. The same thing holds good for programming. In my article Software Programming can be humbling. Point 7 talks about assertions.

The line above shows the affect of a bug in a software system. The line represents the state of the system. The bug is activated at the point "bad" in the line. The earlier we catch the bug, the better the chances of avoiding an ill affect later. Assertions can help catch bugs early and leave the system in a more stable state. This enables us to debug a little better.

In "C" assertions are supported by including assert.h.
assert(condition), takes in one parameter. From the man page of assert

The macro assert() generates no code, and hence does  nothingat all.  Otherwise, the macro assert() prints an error message to stan-dard output and terminates the program by calling abort() if expressionis false (i.e., condition equal to zero).The  purpose  of  this macro is to help the programmer find bugs in hisprogram.  The  message  "assertion  failed  in  file