MISRA C:2012 Dir 4.6
typedefs
that indicate size and signedness should be used in place of the basic numerical types
描述
指令定义
typedefs
that indicate size and signedness should be used in place of the basic numerical types 1
.
理由
当分配的内存量很重要时,使用指示其长度的类型可以清楚地知道为每个对象预留了多少存储空间。
Polyspace 实现
Polyspace® 将整数、浮点数和复数视为基本数值类型。如果基本数值类型的数据类型不包括有效的位数或包含常用的与大小相关的词,则报告为违规。有效位数必须是 8 的倍数。支持的与大小相关的词包括位、字节、字和其他常用关键字。
Polyspace 检查函数原型、类型声明、变量声明、转换表达式和 sizeof
运算符中的数据类型。
Polyspace 不报告以下使用情况的违规行为:
在类型转换中使用 complex 和 imaginary 类型。
使用类型
size_t
和ptrdiff_t
。使用普通的
char
类型。将
int
作为main()
函数的返回类型。将
int
作为main()
函数的参数类型。使用已知的布尔类型,如
bool
或_Bool
。
标题 stdint.h
定义了一些固定宽度的类型,这些类型表示某种类型的最小或最快的可能大小。示例包括 int_least8_t
、unit_fast_8_t
以及类似类型。请参阅 Fixed with integer types。如果使用这些类型,Polyspace 会报告违规。例如,此代码将 24 位变量 var_globe24
声明为至少有 8 位的整数。
int_least8_t var_glob24;
故障排除
如果您预期会出现违规,但未看到该违规,请参阅诊断为何编码规范违规未按预期显示。
示例
检查信息
组:代码设计 |
类别:建议 |
AGC 类别:建议 |
版本历史记录
在 R2014b 中推出1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.
The MISRA coding standards referenced in the Polyspace Bug Finder™ documentation are from the following MISRA standards:
MISRA C:2004
MISRA C:2012
MISRA C:2023
MISRA C++:2008
MISRA C++:2023
MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.