By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,384 Members | 671 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,384 IT Pros & Developers. It's quick & easy.

assert and ndebug - how to

P: 1
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!
Sep 30 '15 #1
Share this Question
Share on Google+
2 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
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.
Oct 2 '15 #2

Expert 100+
P: 2,398
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.
Oct 3 '15 #3

Post your reply

Sign in to post your reply or Sign up for a free account.