assert and ndebug - how to

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JabirFarah
    New Member
    • Sep 2015
    • 1

    assert and ndebug - how to

    Hi guys,
    i apologize for my lack of knowledge or how silly this question may be, but can someone explain to me how does ndebug cancel the assert function of C? and an example would be most useful, if possible of course.
    Thank you for your time!
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Look in assert.h for the code for the assert function.

    NDEBUG would be defined on the compiler command line. It has the effect of making the assert function null. It's the 1968 way of doing a release build.

    Comment

    • donbock
      Recognized Expert Top Contributor
      • Mar 2008
      • 2427

      #3
      The C Standard says that assert() is a macro. Presence of the NDEBUG macro alters the definition of assert() such that it doesn't do anything.

      Even when presence of NDEBUG prevents assertions from executing, they still serve to document assumptions in the source code. Some static analyzers use assertions as hints for predicting execution paths through the code.

      Comment

      Working...