简体   繁体   English

规则 14.2 for 循环应为 MISRA C 2012 格式良好

[英]Rule 14.2 A for loop shall be well-formed for MISRA C 2012

Why my tool for analysis of the rule for MISRA report a possible violation for this for loop ?为什么我的 MISRA 规则分析工具报告了此 for 循环的可能违规? For example例如

for(; i != 0 ; i = f(r) ) { int a = 9 + i; }

According to MISRA C 2012 document, the third clause of a for statement shall be an expression whose only persistent side effect is to modify the value of the loop counter and it shall not use objects that are modified in the for loop body.根据 MISRA C 2012 文档, for语句的第三个子句应该是一个表达式,其唯一持久的副作用是修改循环计数器的值,并且它不得使用在for循环体中修改的对象。 These restrictions also apply to all functions called within for statement.这些限制也适用于在for语句中调用的所有函数。

From the code you provided, I can guess, that f(r) function call contains side effects, such as modification of global variables or r argument.根据您提供的代码,我可以猜测f(r)函数调用包含副作用,例如修改全局变量或r参数。 All other requirement described in rule 14.2 text are met.满足规则 14.2 文本中描述的所有其他要求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM