473,472 Members | 2,039 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

assert()

In a nutshell, what is the behavior of the assert() macro ***as proscribed
by the C89 Standard*** (which I don't have)? Of course, it doens't appear
in the C++ Standard since it's inherited from C. Hence my inquiry about the
C Standard even though I care about this from a C++ perspective...

Specifically, I'm wondering what the Standard has to say about when the
compiler ignores asserts and when the compiler is to compile them in and
generate code for them. After all, the Standard says nothing debug vs.
release builds...
Jul 22 '05 #1
4 22702
On Wed, 19 Nov 2003 12:50:40 -0700, Dave wrote:
In a nutshell, what is the behavior of the assert() macro ***as
proscribed by the C89 Standard*** (which I don't have)? Of course, it
doens't appear in the C++ Standard since it's inherited from C. Hence
my inquiry about the C Standard even though I care about this from a C++
perspective...

Specifically, I'm wondering what the Standard has to say about when the
compiler ignores asserts and when the compiler is to compile them in and
generate code for them. After all, the Standard says nothing debug vs.
release builds...


assert is defined as ((void)0) if the macro NDEBUG is defined at the point
where <assert.h> is included. If NDEBUG is not defined, assert is supposed
to print an error message to stderr and call abort(). The format of the
error message is implementation-defined, but it must include the source
file name and line number (and function name in C99).
Jul 22 '05 #2
"Dave" <be***********@yahoo.com> wrote in message news:<vr************@news.supernews.com>...
In a nutshell, what is the behavior of the assert() macro ***as proscribed
by the C89 Standard*** (which I don't have)? Of course, it doens't appear
in the C++ Standard since it's inherited from C. Hence my inquiry about the
C Standard even though I care about this from a C++ perspective...

Specifically, I'm wondering what the Standard has to say about when the
compiler ignores asserts and when the compiler is to compile them in and
generate code for them. After all, the Standard says nothing debug vs.
release builds...


I don't have the C standard either, but in the C++ standard,
17.4.2.1/2 mentions the NDEBUG macro. And my understanding is that
when this macro is not defined, code is generated for an assert, and
when NDEBUG is defined code is not generated.

This ties in with the contents of my implementation's assert.h file.

GJD
Jul 22 '05 #3
Checkout the following article for assert handling:

http://www.eventhelix.com/RealtimeMa...y_contract.htm

Sandeep
--
http://www.EventHelix.com/EventStudio
EventStudio 2.0 - Generate Sequence Diagrams and Use Case Diagrams in PDF
Jul 22 '05 #4
EventHelix.com wrote:
Checkout the following article for assert handling:

http://www.eventhelix.com/RealtimeMa...y_contract.htm

Sandeep


Their non-debugging macros do not *not* evaluate their arguments; e.g.

ASSERT(strlen(foo) > 10);

gets expanded to

strlen(foo) > 10;

when the _DEBUG flag is not defined. Their code is full of similar
examples where assert macros generate overhead no matter what. Pretty
poor example.

Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
by: Fábio Mendes | last post by:
I'm sorry if it's an replicate. Either my e-mail program is messing with things or the python-list sent my msg to /dev/null. I couldn't find anything related in previous PEP's, so here it goes a...
3
by: Thomas Guettler | last post by:
Hi, Python 2.3.3 (#1, Feb 5 2005, 16:22:10) on linux2 >>> assert 0, "foo" Traceback (most recent call last): File "<stdin>", line 1, in ? AssertionError: foo >>> assert(0, "foo") >>>
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...
5
by: Alex Vinokur | last post by:
Here are two programs. --- foo1.c --- #include <assert.h> #define FOO 10 int main() { assert (15 < FOO); return 0; }
47
by: Rob Thorpe | last post by:
In general, is it considered bad practice to use asserts in production code? What about writing a macro that does the same as assert but continues to work regardless of the state of NDEBUG? I...
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...
12
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, I saw a couple of form of assert in code on Windows, 1. ASSERT; 2. assert; 3. _ASSERT; 4. _assert.
30
by: Tomás Ó hÉilidhe | last post by:
In C89, do we have to pass an int as an argument to assert? I've got code at the moment that does an assertion on pointer, e.g.: assert(p); , but I'm wondering if I should change that to: ...
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:...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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: 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: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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 ...

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.