功能齐全的 C++ 断言对话框?

发布于 2024-07-24 08:00:33 字数 175 浏览 3 评论 0原文

我正在为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

窝囊感情。 2024-07-31 08:00:33

请参阅 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.

じее 2024-07-31 08:00:33

这是我为 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.

他夏了夏天 2024-07-31 08:00:33

_ASSERTE 完全破坏了您想要的位置 - 但不符合您的其他要求标准。

_ASSERTE 很好,因为它显示实际的断言文本以及文件名和行号。 这意味着您可以执行以下操作:

_ASSERTE(bufLen > 0 && "bufLen needs to be greater than 0");

_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");
哭泣的笑容 2024-07-31 08:00:33

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?

山色无中 2024-07-31 08:00:33

我发布了 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;
}

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.

#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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文