473,473 Members | 1,837 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

assert and ndebug - how to

1 New Member
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
2 1636
weaknessforcats
9,208 Recognized Expert Moderator Expert
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
donbock
2,426 Recognized Expert Top Contributor
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

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

Similar topics

6
by: Alexander Malkis | last post by:
Why do programmers like to use NDEBUG instead of DEBUG? -- Best regards, Alex. PS. To email me, remove "loeschedies" from the email address given.
13
by: Matthias Kaeppler | last post by:
Hi, why can I use assert from <cassert> without resolving the std:: namespace? E.g.: #include <cassert> int main() { assert(true); // shouldn't this be: std::assert(true) ?
3
by: Tony Johansson | last post by:
Hello Experts! I'm reading a book called programming with design pattern revealed by Tomasz Muldner and here I read something that I don' work. The text in the book says "To offer the...
21
by: Giuseppe | last post by:
is assert() for debug only or not? Is it possible that I have seen the use of assert() in the Borland c++ 32 compiler (so assert is not for debug only)?
27
by: Daniel Vallstrom | last post by:
I'm having problems with inconsistent floating point behavior resulting in e.g. assert( x > 0.0 && putchar('\n') && x == 0.0 ); holding. (Actually, my problem is the dual one where I get...
28
by: lovecreatesbeauty | last post by:
Besides printing out for example " a.out: p113.c:8: main: Assertion `0' failed. Aborted " and a switch option NDEBUG, what other benefits does assert() provide in any scope of designing,...
13
by: priyanka | last post by:
Hi there, Can anyone show me how the assert() function works ? I need to develop my own assert() function instead of using the one defined in the assert.h file. It would be great if anyone could...
6
by: Joseph Turian | last post by:
I've been using assert liberally throughout my code. Then, upon compiling with -NDEBUG, I found that my program had different output. Why? Because -NDEBUG disables assert, but I had (at least) one...
9
by: pereges | last post by:
Ok, so once I'm done debugging my code(split across multiple modules) using the assert macro, I would want to switch off all the assert macros ued in the program. Does this mean I have to include:...
32
by: bingfeng | last post by:
hello, please see following two code snatches: 1. int foo (const char* some) { assert(some); if (!some) { return -1; //-1 indicates error }
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.