views:

282

answers:

4

Hi,

I'm looking for a good, fully featured C++ assert macro for VisualStudio. With features like be able to ignore an assert once or always, to be able to break exactly where the macro gets called (and not inside macro code), and getting a stack trace.

Before I have to hunker down and write one, I figured I'd ask if anyone knows about any available ones out there.

Any suggestions?

Thanks!

A: 

OpenOffice has some assertion code that has an option of logging to a message box. Probably not exactly what you want, but instructive maybe?

John Weldon
Hi John! I realized I didn't specify the platform in my original question. So I updated it.
Steve the Plant
+1  A: 

Here's a link to an article I wrote for DDJ that described, among other things, a library that does much of what you're looking for. Although I don't just use macros, I also implement functions in a DLL.

http://www.ddj.com/architect/184406106

The article from a few years ago and, although I have made many additions, I still use it very liberally in my everyday code.

John Dibling
A: 

_ASSERTE breaks exactly where you want it - but does not meet your other criteria.

_ASSERTE is nice because it displays the actual assertion text along with the filename and line number. This means you can do this:

_ASSERTE(bufLen > 0 && "bufLen needs to be greater than 0");
sean e
+5  A: 

See Charles Nicholson's blog for a good discussion of an assert macro. His solution breaks the debugger at the faulting line of code (and not inside the failed assertion handler), and he also solves the problem of not getting warnings about unused variables when assertions are disabled without incurring any runtime costs.

Adam Rosenfield
Works for me! The article is really well written. The code even has a way set your own handler, so that is where I'd add a dialog box with options.
Steve the Plant