MISRA C Rule5.6 3448 Rule6.1 0634
typedef的声明不是在一个头文件中;
struct/union中的位域没有显式声明为unsigned或signed。
工具/原料
Rule5.6 3448 Rule6.1 0634
MISRA C:2012
Rule5.6 3448
规则与等级对应关系(QAC)

3448 Declaration of typedef '%s' is not in a header file although it is used in a definition or declaration with external linkage.
在多个地方定义一个typedef是没有意义的。如果这个typedef是用来声明/定义一个具有 外部链接 属性的对象/函数, 那么它应该被定义在一个头文件中。因为这可能意味着在多个 翻译单元中,都会使用到这个 '类型定义'。这样做比直接在每个源文件中都插入一个局部声明更安全、更容易维护。
官方示例

编程规范修改举例

Rule6.1 0634
规则与等级对应关系(QAC)

0634 [I] Bit-fields in this struct/union have not been declared explicitly as unsigned or signed.
没有显式指定位域的符号类型。
ISO:C 标准中声明位域的类型可以是以下类型的任何一种:
int/unsigned int/signed int。
通常情况下,把int作为signed类型实现。但是,使用int定义一个位域时,实现时可能是signed类型或unsigned类型。具体由实现定义。 为排除这种不确定性,最好在实际情况中把位域的符号类型显式指定为unsigned int祸signed int类型。
实际情况中,编译器也支持其他整型(例如signed char, unsigned char)。struct或union声明的位域为char, short, int, long或long long类型时,生成消息0634。 在struct或union的声明中此消息只会出现一次。

编程规范修改举例
