为什么"继续]被认为是一个C违反MISRA C:2004? [英] Why "continue" is considered as a C violation in MISRA C:2004?

查看:319
本文介绍了为什么"继续]被认为是一个C违反MISRA C:2004?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MISRA 14.5说道continue语句,不得使用。谁能解释一下原因吗?
谢谢你。

MISRA 14.5 says continue statement must not be used. Can anyone explain the reason? Thank you.

推荐答案

这是因为古辩论关于转到 ,无条件分支和意大利面条code,这已经持续了40年左右。 转到继续和多个收益语句都被认为或多或少同样糟糕。

It is because of the ancient debate about goto, unconditional branching and spaghetti code, that has been going on for 40 years or so. goto, continue, break and multiple return statements are all considered more or less equally bad.

世界编程界的共识已经大致结束了是这样的:我们认识到,如果你知道你在做什么,你可以使用该语言的这些功能​​,而无需编写意大利面条code。但是,我们仍然鼓励他们,因为有一个大的机会,人谁不知道他们在做什么,将要使用的功能(如果有),然后创建意大利面条。我们也鼓励他们,因为他们是多余的功能:你可以明显地写程序,而无需使用它们

The consensus of the world's programming community has roughly ended up something like: we recognize that you can use these features of the language without writing spaghetti code if you know what you are doing. But we still discourage them because there is a large chance that someone who doesn't know what they are doing are going to use the features if they are available, and then create spaghetti. And we also discourage them because they are superfluous features: you can obviously write programs without using them.

由于MISRA-C的目的是对关键系统,MISRA-C:2004年已经禁止尽可能多的无条件转移功能尽可能的办法。因此,转到继续和多收益者禁用。如果有相同的循环中一个休息,只被允许。

Since MISRA-C is aimed towards critical systems, MISRA-C:2004 has the approach to ban as many of these unconditional branch features as possible. Therefore, goto, continue and multiple returns were banned. break was only allowed if there was a single break inside the same loop.

然而的,在MISRA-C:2011,这是目前正在评估报告草案,该委员会已考虑让所有这些功能再次,与后藤应该只允许有限制向下跳,从来没有向上。从该委员会的理由说,现在有工具(即静态分析仪)足够聪明,发现不良程序流程,所以关键字可以允许的。

However, in the "MISRA-C:2011" draft which is currently under evaluation, the committee has considered to allow all these features yet again, with a restriction that goto should only be allowed to jump downwards and never upwards. The rationale from the committee said that there are now tools (ie static analysers) smart enough to spot bad program flow, so the keywords can be allowed.

其中goto争论依然强劲...

The goto debate is still going strong...

这篇关于为什么"继续]被认为是一个C违反MISRA C:2004?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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