472,805 Members | 943 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 software developers and data experts.

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 22667
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:...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.