功能齐全的 C++ 断言对话框?
我正在为 VisualStudio 寻找一个良好的、功能齐全的 C++ 断言宏。 具有诸如能够一次或始终忽略断言、能够准确中断调用宏的位置(而不是在宏代码内部)以及获取堆栈跟踪等功能。
在我必须坐下来写一篇之前,我想我会问是否有人知道那里有可用的。
有什么建议么?
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
请参阅 Charles Nicholson 的博客,了解有关
断言
宏。 他的解决方案在错误代码行处中断了调试器(而不是在失败的断言处理程序内),并且他还解决了禁用断言时不会收到有关未使用变量的警告的问题,而不会产生任何运行时成本。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.这是我为 DDJ 撰写的一篇文章的链接,该文章除其他外还描述了一个可以完成您正在寻找的大部分功能的库。 虽然我不只使用宏,但我也在 DLL 中实现函数。
http://www.ddj.com/architect/184406106
几年前的文章而且,尽管我做了很多补充,但我仍然在日常代码中非常自由地使用它。
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.
_ASSERTE 完全破坏了您想要的位置 - 但不符合您的其他要求标准。
_ASSERTE 很好,因为它显示实际的断言文本以及文件名和行号。 这意味着您可以执行以下操作:
_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:
OpenOffice 有一些断言代码,可以选择记录到消息框。 可能不完全是你想要的,但也许有启发性?
OpenOffice has some assertion code that has an option of logging to a message box. Probably not exactly what you want, but instructive maybe?
我发布了
PPK_ASSERT
。 虽然它不会打开对话框,但在 Windows 上,默认处理程序会打开一个控制台,您可以在其中读取断言消息并决定采取哪个操作。I released
PPK_ASSERT
. While it doesn't open a dialog box, on Windows the default handler opens a console where you get to read the assertion message and get to decide which action to take.