Re: Assertion in DEBUG and RELEASE
- From: "Severian [MVP]" <severian@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 29 Apr 2005 04:46:29 GMT
On Thu, 28 Apr 2005 21:17:19 +0200, "Guido Stercken-Sorrenti [MVP
VC++]" <mspbn@xxxxxxxxxxxxxxxxxxxxx> wrote:
>> Recently, I came across a situation, that at some point in the code, that
>> my program start crashing BUT only in Release
>> version, that is also not always, but some particular point. Now, you can
>> imagine it is very hard to find such problem. The
>> code is like this, I was getting a pointer, and check with an ASSERT
>> statement that the pointer is valid or not. Now, in DEBUG
>> version, it works fine all the time, even at that particular situation,
>> while debugging or just with run. But release version
>> gives the pointer is invalid, and not throwing any exception or assertion,
>> so I was not able to go to that particular
>> function, or source line quickly. My question is:
>> Is it good to check an assertion at the Release version also? Because MFC
>> ASSERT or CRT LIB's _ASSERT macros will work only in
>> DEBUG version and not in release? But if we use _assert, CRT-L function
>> the it will give assertion in Release version also.
>> So, is it OK to get the assertion also in Release version?
>
>Generally, assertions are used for spotting coding bugs during development,
>not runtime errors. Those bugs should be fixed for a release build, that's
>why assertions (which also make your code slower) are removed from release
>builds.
>
>The reason why your code fails in a release build is most probably an
>uninitialized pointer: The debug CRT initializes that memory with NULL,
>that's why it works in a debug build (if you test against NULL) but fails in
>release build.
In VC7.1 at least, uninitialized data is filled with 0xcc... in a
debug build.
The OP can always add if statements or his own macros that will be
compiled into both debug and release builds.
Note that assert(x=y) (or any assert that modifies anything) will
cause different behavior in debug and release builds.
Also notable (but not necessarily germane in this case): compilers
always have bugs, and the optimizing compilers generally have
different bugs than the debug compiler.
>To spot that kind of bug, see the following FAQ on CodeGuru:
>http://www.codeguru.com/forum/showthread.php?s=&threadid=269905
--
Phillip Crews aka Severian
Microsoft MVP, Windows SDK
Posting email address is real, but please post replies on the newsgroup.
.
- References:
- Assertion in DEBUG and RELEASE
- From: Tom Alter
- Re: Assertion in DEBUG and RELEASE
- From: Guido Stercken-Sorrenti [MVP VC++]
- Assertion in DEBUG and RELEASE
- Prev by Date: Re: Book Suggestions
- Next by Date: Re: _ecvt, _gcvt and _fcvt problem
- Previous by thread: Re: Assertion in DEBUG and RELEASE
- Next by thread: Help! Windows Newbeeeee....
- Index(es):
Relevant Pages
|
Loading