MISRA C规则12.2 - 假阳性的警告? [英] Misra C Rule 12.2 - false positive warning?

查看:394
本文介绍了MISRA C规则12.2 - 假阳性的警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的CCS 6.1 ARM编译器(用于LM3Sxxxx的Stellaris)抛出一个警告:

My CCS 6.1 ARM compiler (for LM3Sxxxx Stellaris) throws a warning :

MISRA规则12.2。一位前pression的值应根据评估的任何命令,该标准允许相同的

"MISRA Rule 12.2. The value of an expression shall be the same under any order of evaluation that the standard permits"

为以下code:

typedef struct {
  ...
  uint32_t bufferCnt;
  uint8_t buffer[100];
  ...
} DIAG_INTERFACE_T;

static DIAG_INTERFACE_T diagInterfaces[1];

...
DIAG_INTERFACE_T * diag = &diagInterfaces[0];
uint8_t data = 0;
diag->bufferCnt = 0;
diag->buffer[diag->bufferCnt++] = data; // line where warning is issued
...

我看不到我的code的一个问题。它是假阳性或我的错误吗?

I don't see a problem in my code. Is it false positive or my bug?

推荐答案

虽然你并不表明它,这是MISRA-C:2004年,第12.2,现在是MISRA-C:2012规则13.2。作为oauh说,这已无关的评价的顺序。

Although you don’t indicate it, this is MISRA-C:2004, Rule 12.2, and is now MISRA-C:2012 Rule 13.2. As oauh says, this has nothing to do with "order of evaluation".

我强烈建议指MISRA-C:2012,即使你都必须MISRA-C:2004标准,有MISRA-C:2012年左右会有所帮助,因为它澄清了许多的准则,包括额外的理由,解释和实施例。

I highly recommend referring to MISRA-C:2012 even if you are required to be MISRA-C:2004 compliant, having MISRA-C:2012 around helps, because it has clarified many of the guidelines, including additional rationale, explanations and examples.

您不应该使用编译器只检查MISRA-C的兼容性,它的不错,但编译器#1的目标不是要提醒你的所有,是专注于利用的陷阱和语言的陷阱(优化)。他们不是很precise要么,因为在这种情况下。此外,还有很多不确定的行为,在整个翻译单元,编译器不能发出警告。它最好也使用专用的MISRA静态分析工具,一个是没有具体的编译器,但是,从来看,没有一个特定的实施ISO C标准点发出警告所有未predictable结构。

You should not be using a compiler to solely check for MISRA-C compliancy, its nice, but compilers #1 goal is not to warn you about all the traps and pitfalls of the language it is dedicated to take advantage of (optimization). They're not very precise either, as in this case. Also, there are many undefined behaviors across translation units, compilers cannot warn about. Its best to also use a dedicated MISRA Static analysis tool, one that is not compiler specific, but that warns about all unpredictable constructs from the ISO C standards point of view, not a particular implementation.

由于oauh也说了,这是违反MISRA-C的:规则12.13,也就是现在的MISRA-C:2012规则13.3已放宽到允许++和 - 与其他运营商混合,前提是该++或 - 是副作用的唯一来源(在你的情况下,分配也是用C术语的副作用)。

As oauh also said, this is a violation of MISRA-C:Rule 12.13, which is now MISRA-C:2012 Rule 13.3 which has been relaxed to permit ++ and -- to be mixed with other operators, provided that the ++ or -- is the only source of side-effects (in your case the assignment is also a side effect in C terminology).

该规则并不重要,也就是它的定义良好的行为,但是从preFIX版和后缀版本可能会导致混乱所造成的不同的价值观,因此它是顾问,意思是没有正式的偏差是必需的(同样,一个体面的MISRA-C的工具将允许你想喝preSS这个特殊的违规)。

The Rule is not critical, i.e. its well defined behavior, but the different values resulting from the prefix version and the postfix version can cause confusion, thus it is "advisory" meaning no formal deviation is required (again, a decent MISRA-C tool would allow you to suppress this particular violation).

这篇关于MISRA C规则12.2 - 假阳性的警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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