问题描述
Cppcheck允许您创建自己的规则文件,但我不知道cppcheck的功能暴露了多少。
Cppcheck allows you to create your own rules files, but I don't know how much of cppcheck's functionality is exposed.
强制执行或规则?
推荐答案
所有MISRA / JSF规则和指令作为cppcheck规则,大多数只是直接的限制某些C语言特性和结构,或者是风格相关的(一些注意:空格前/后./->单行,使用联合提供访问内存的不同方法,在char之前存在unsigned / signed等)。
You won't be able to implement all MISRA/JSF rules and directives as cppcheck rules, mostly only the straightforward ones restricting certain C language features and constructions or that are style-related (some that come to mind: spaces before/after ./->, # of arguments on a single line, use of unions to provide different methods of accessing memory, presence of unsigned/signed before char, etc).
用户几乎把它钉在一个另一个问题触摸cppcheck:不是一切都可以表示/简化为模式。依赖于自定义规则的模式,很难处理和检测更高级别的问题,例如与类型(例如sizeof())相关的类型;解析和收集用作类型表示的令牌(typedef,枚举),继承(例如类,包括派生类,用作虚拟和非虚拟) 和范围。那些需要硬编码到cppcheck(你可以总是fork cppcheck ...)
User Ira Baxter pretty much nailed it in a comment on another question touching cppcheck: not everything can be represented/simplified as a pattern. Relying on patterns for custom rules makes it difficult to handle and detect higher level issues, related for example to types (e.g. sizeof() on types; you would have to parse and collect tokens (typedefs, enums) used as a type representation), inheritance (e.g. classes, incl. derived ones, used both as virtual and non-virtual), and scope. Those need to be hard-coded into cppcheck (you could always fork cppcheck...)
在任何情况下,你是否接触过MISRA(或JSF)规则?这是项目的要求吗?如果没有,您可以获取一份MISRA指南(您已经拥有JSF指南),并检查您可以使用PCRE模式实现的指南。如果这是一个要求,我建议您投资一个商业产品,检查MISRA / JSF指南并使用这两种工具。
In any case, have you touched MISRA (or JSF) rules? Is this a requirement for a project? If not, you could grab a copy of the MISRA guidelines (you already have the JSF ones) and check the ones you can implement using PCRE patterns. If it is a requirement, I suggest you "invest" in a commercial product that does check for MISRA/JSF guidelines and use both tools.
最后一点:不需要所有的MISRA / JSF规则,并且许多工具只留下一小部分。
A final note: you don't need all the MISRA/JSF rules, and many tools leave a small percentage of those out.
这篇关于cppcheck的规则集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!