Re: assert
From: Carl Daniel [VC++ MVP] (cpdaniel_remove_this_and_nospam_at_mvps.org.nospam)
Date: 04/14/04
- Next message: Roy Fine: "Re: doubles or not"
- Previous message: Roy Fine: "Re: Questions of VC"
- In reply to: bdg: "assert"
- Next in thread: bdg: "Re: assert"
- Reply: bdg: "Re: assert"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 13 Apr 2004 20:31:53 -0700
bdg wrote:
> MSDN says that "The assert routine is available in both the release
> and debug versions of the C run-time libraries."
>
> How can it be true that "The assert routine is available in both the
> release and debug versions of the C run-time libraries"? My testing
> shows that assert() statements are only executed when compiling
> project into Debug version.
It is kind of silly. By "available" they mean that the program will compile
and link with either RTL. Of course, assert() doesn't do anything in a
release build.
>
> Why does _DEBUG has to be defined since if building project into Debug
> version, no need to define _Debug any more?
Unfortunately, there are two macros:
NDEBUG is defined in release builds (mandated by the C and C++
standards)
_DEBUG is defined in debug builds (VC++ convention).
>
> "Two other assertion macros, _ASSERT and _ASSERTE, are also
> available, but they only evaluate the expressions passed to them when
> the _DEBUG flag has been defined."
>
> When to use _ASSERT or _ASSERTE, instead of assert?
Personal preference, mostly. assert() evaluates only when NDEBUG is not
defined (kinda backwards, eh?), while these others evaluate only when _DEBUG
is defined. In the end, they all do about the same thing. Personally, I'd
stick to assert() since it's defined by the C and C++ standards and is
therefore portable to other systems.
-cd
- Next message: Roy Fine: "Re: doubles or not"
- Previous message: Roy Fine: "Re: Questions of VC"
- In reply to: bdg: "assert"
- Next in thread: bdg: "Re: assert"
- Reply: bdg: "Re: assert"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|