主要内容

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

MISRA C:2012 Rule 2.3

A project should not contain unused type declarations

描述

默认 Polyspace® as You Code 分析中反激活了此检查项。请参阅Checkers Deactivated in Polyspace as You Code Analysis (Polyspace Access)

规则定义

A project should not contain unused type declarations 1 .

理由

如果声明了一个类型但未使用,则评审不知道该类型是冗余的还是错误地未使用。

Polyspace 实现

如果您的代码中仍未使用 Polyspace,则 typedef 会报告违反此规则。

故障排除

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

示例

全部展开

signed short unusedType (void){

    typedef signed short myType;   /* Non-compliant */
    return 67;

}

signed short usedType (void){

    typedef signed short myType;  /* Compliant */
    myType tempVar = 67;
    return tempVar;

}

在此示例中,在 unusedType 函数中,typedef 语句定义了一个新的局部类型 myType。但是,函数中从未使用过该类型。因此,违反了该规则。

usedType 函数中,并未违反该规则,因为使用了新类型 myType

检查信息

组:未使用的代码
类别:建议
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.