主要内容

本页翻译不是最新的。点击此处可查看最新英文版本。

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.

理由

当分配的内存量很重要时,通过使用特定长度的类型可以明确为每个对象保留多少存储空间。

Polyspace 实现

此规则检查项会在变量或函数声明和定义中标记基本数据类型的使用。此规则会强制应用 typedef

此规则检查项不会在 typedef 语句自身中标记基本类型的使用。

故障排除

如果您预计存在违规,但未看到该违规,请参阅Diagnose Why Coding Standard Violations Do Not Appear as Expected

示例

全部展开

typedef unsigned int uint32_t;

int x = 0;       /* Non compliant */
uint32_t y = 0;  /* Compliant */

在此示例中,x 的声明不合规,因为它直接使用了基本类型。

检查信息

组:代码设计
类别:建议
AGC 类别:建议

版本历史记录

在 R2014b 中推出

全部展开