多语言展示
当前在线:497今日阅读:2今日分享:38

MISRA C Rule­5.6 3448 Rule­6.1 0634

typedef的声明不是在一个头文件中; struct/union中的位域没有显式声明为unsigned或signed。
工具/原料
1

Rule­5.6 3448 Rule­6.1 0634

2

MISRA C:2012

Rule­5.6 3448
1

规则与等级对应关系(QAC)

3

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是用来声明/定义一个具有 外部链接 属性的对象/函数, 那么它应该被定义在一个头文件中。因为这可能意味着在多个 翻译单元中,都会使用到这个 '类型定义'。这样做比直接在每个源文件中都插入一个局部声明更安全、更容易维护。

4

官方示例

5

编程规范修改举例END

Rule­6.1 0634
1

规则与等级对应关系(QAC)

2

0634 [I] Bit-fields in this struct/union have not been declared explicitly as unsigned or signed. 没有显式指定位域的符号类型。

3

ISO:C 标准中声明位域的类型可以是以下类型的任何一种:int/unsigned int/signed int。通常情况下,把int作为signed类型实现。但是,使用int定义一个位域时,实现时可能是signed类型或unsigned类型。具体由实现定义。 为排除这种不确定性,最好在实际情况中把位域的符号类型显式指定为unsigned int祸signed int类型。

4

实际情况中,编译器也支持其他整型(例如signed char, unsigned char)。struct或union声明的位域为char, short, int, long或long long类型时,生成消息0634。 在struct或union的声明中此消息只会出现一次。

5

编程规范修改举例END

推荐信息