Jump to content

Assert.h

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Fresheneesz (talk | contribs) at 15:44, 3 June 2006 (create page). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

Include the standard header <assert.h> to define the macro assert, which is useful for diagnosing logic errors in the program. You can eliminate the testing code produced by the macro assert without removing the macro references from the program by defining the macro NDEBUG in the program before you include <assert.h>. Each time the program includes this header, it redetermines the definition of the macro assert.

If the int expression test equals zero, the macro writes to stderr a diagnostic message that includes:

  • the text of test
  • the source filename (the predefined macro __FILE__)
  • the source line number (the predefined macro __LINE__)

It then calls abort.