assert() 带有消息 [英] assert() with message

查看:47
本文介绍了assert() 带有消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到某处断言以下列方式与消息一起使用:

I saw somewhere assert used with a message in the following way:

assert(("message", condition));

这似乎很好用,只是 gcc 抛出以下警告:

This seems to work great, except that gcc throws the following warning:

warning: left-hand operand of comma expression has no effect

如何停止警告?

推荐答案

使用 -Wno-unused-value 停止警告;(选项 -Wall 包括 -Wunused-value).

Use -Wno-unused-value to stop the warning; (the option -Wall includes -Wunused-value).

我认为更好的是使用另一种方法,例如

I think even better is to use another method, like

assert(condition && "message");

这篇关于assert() 带有消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆