assert()

D

Dave

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...
 
S

Simon Saunders

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).
 
G

Gavin Deane

Dave said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top