help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: assert


From: Rolf Magnus
Subject: Re: assert
Date: Wed, 05 May 2004 23:00:24 +0200

BlueDoze wrote:

> Hellooo,
> 
> I want to know the exact *correct* behaviour of the assert statement
> given that its argument value will be "0", should it core dumps the
> application only ?.

Here's what the ISO C99 standard has to say about it:

7.2.1.1 The assert macro

1 Synopsis 

        #include <assert.h>
        void assert(scalar expression);

2 Description

The assert macro puts diagnostic tests into programs; it expands to a
void expression. When it is executed, if expression (which shall have a
scalar type) is false (that is, compares equal to 0), the assert macro
writes information about the particular call that failed (including the
text of the argument, the name of the source file, the source line
number, and the name of the enclosing function -- the latter are
respectively the values of the preprocessing macros __FILE__ and
__LINE__ and of the identifier __func__) on the standard error stream
in an implementation-defined format.159) It then calls the abort
function.

3 Returns

The assert macro returns no value.

Forward references: the abort function (7.20.4.1).

> Can I manage its effect ?

I'll again answer with a quote from the standard:

The header <assert.h> defines the assert macro and refers to another
macro,

        NDEBUG

which is not defined by <assert.h>. If NDEBUG is defined as a macro name
at the point in the source file where <assert.h> is included, the
assert macro is defined simply as

        #define assert(ignore) ((void)0)

The assert macro is redefined according to the current state of NDEBUG
each time that <assert.h> is included.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]