如何告诉gcc在没有中断的情况下对switch / case语句发出警告(或失败)? [英] How can I tell gcc to warn (or fail) on switch/case statements without a break?

查看:322
本文介绍了如何告诉gcc在没有中断的情况下对switch / case语句发出警告(或失败)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个复杂的开关语句,我忘了在之一的结尾放置 break case s。这是相当合法的,因此我有一个下落到下一个情况。

I have a complicated switch statement, and I forgot to put a break at the end of one of the cases. This is quite legal, and as a result I had a fall-through to the next case.

如果我忽略放置一个 break 语句,任何方式有gcc警告(或更好,失败)

Is there any way to have gcc warn (or even better, fail) if I neglect to put a break statement?

我意识到有很多有效的用例(我经常在我的代码中使用它们),如这个问题,所以显然这样的警告(或失败)需要一个简单的豁免,这样我可以很容易地说, 我想在这里落下。

I realize that there are many valid use cases (and I use them often in my code), as exemplified in this question, so obviously such a warning (or failure) would need a simple waiver so that I could easily say, "I do want to fall-through here."

有没有办法告诉gcc这样做?

Is there any way to tell gcc to do this?

推荐答案

http://gcc.gnu.org上有关于此类功能(-Wswitch-break)的讨论/bugzilla/show_bug.cgi?id=7652 。但它似乎还没有实现

There's a discussion about such a feature (-Wswitch-break) at http://gcc.gnu.org/bugzilla/show_bug.cgi?id=7652. But it doesn't seem to be implemented yet

这篇关于如何告诉gcc在没有中断的情况下对switch / case语句发出警告(或失败)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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