Assertions in release builds?

D

Duncan Smith

Last week, I got reports back of errors in a patch I let someone try
out (release dll, but not from the build machine). Turns out it was
some Debug::Assert statements firing.

In umanaged code, I'd always understood that assertions were only
fired in debug builds and would compile down to NOPs in release builds
(for good reasons)

Now it looks as though I have to be careful to code assertions
conditionally?

#ifdef _DEBUG
Debug::Assert( false );
#endif

as opposed to

ASSERT( FALSE );

What's the thinking behind the change?

Regards,

Duncan
 
D

David Lowndes

Last week, I got reports back of errors in a patch I let someone try
out (release dll, but not from the build machine). Turns out it was
some Debug::Assert statements firing.

In umanaged code, I'd always understood that assertions were only
fired in debug builds and would compile down to NOPs in release builds
(for good reasons)

Now it looks as though I have to be careful to code assertions
conditionally?

#ifdef _DEBUG
Debug::Assert( false );
#endif

as opposed to

ASSERT( FALSE );

What's the thinking behind the change?

Duncan,

This quirk would appear to be specific to C++/CLI usage. Using
Debug.Assert from C# (I presume VB is the same) doesn't generate any
code in release builds.

The documentation does say "C++ does not support the Debug class
methods." - which in itself seems rather odd because it clearly works
but has the quirk that its not removed in release builds.

This offers some explanation of why the situation is as it is:
http://blog.kalmbachnet.de/?postid=78

There's also a bug report on this here (you might want to add a vote
to it) - note it's still the same with Orcas B2:
http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=98820

Dave
 

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

Top