MISRA C Rule­5.6 3448 Rule­6.1 0634

2025-11-06 23:24:31

typedef的声明不是在一个头文件中;

struct/union中的位域没有显式声明为unsigned或signed。

工具/原料

Rule­5.6 3448 Rule­6.1 0634

MISRA C:2012

Rule­5.6 3448

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

MISRA C Rule­5.6 3448 Rule­6.1 0634

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

官方示例

MISRA C Rule­5.6 3448 Rule­6.1 0634

编程规范修改举例

MISRA C Rule­5.6 3448 Rule­6.1 0634

Rule­6.1 0634

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

MISRA C Rule­5.6 3448 Rule­6.1 0634

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的声明中此消息只会出现一次。

MISRA C Rule­5.6 3448 Rule­6.1 0634

编程规范修改举例

MISRA C Rule­5.6 3448 Rule­6.1 0634

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
相关推荐
  • 阅读量:76
  • 阅读量:97
  • 阅读量:160
  • 阅读量:160
  • 阅读量:115
  • 猜你喜欢