主要内容

MISRA C:2012 Rule 5.9

Identifiers that define objects or functions with internal linkage should be unique

描述

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

规则定义

Identifiers that define objects or functions with internal linkage should be unique 1 .

理由

具有内部链接的标识符仅在声明它们的转换单元中可访问。这些标识符通常被声明为 static。如果这种标识符不唯一,代码可能变得难以理解,并导致意外的结果。

Polyspace 实现

Polyspace 会标记在所有转换单元中不唯一的 static 变量名称。

故障排除

如果您预期会出现违规,但未看到该违规,请参阅诊断为何编码规范违规未按预期显示

示例

全部展开

#include<stdint.h>
#include <assert.h>
static int testGlobal;
void foo(){
static char testGlobal;//Noncompliant	
if(1){
	static char testGlobal;//Noncompliant
}
}

在此示例中,标识符 testGlobal 被用于在三个不同作用域中声明三个变量。因为这些标识符是 static 标识符并且共用一个非唯一名称,所以 Polyspace 会标记该标识符的重复项。

检查信息

组:标识符
类别:建议
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.