功能齐全的 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)
这是我为 DDJ 撰写的一篇文章的链接,该文章除其他外还描述了一个可以完成您正在寻找的大部分功能的库。 虽然我不只使用宏,但我也在 DLL 中实现函数。
http://www.ddj.com/architect/184406106
几年前的文章而且,尽管我做了很多补充,但我仍然在日常代码中非常自由地使用它。
我发布了 PPK_ASSERT
。 虽然它不会打开对话框,但在 Windows 上,默认处理程序会打开一个控制台,您可以在其中读取断言消息并决定采取哪个操作。
#include <pempek_assert.h>
int main()
{
float min = 0.0f;
float max = 1.0f;
float v = 2.0f;
PPK_ASSERT(v > min && v < max, "invalid value: %f, must be between %f and %f", v, min, max);
return 0;
}
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
请参阅 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.