メインコンテンツ

MISRA C:2023 Rule 5.9

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

R2024a 以降

説明

このチェッカーは、既定の Polyspace® as You Code 解析では非アクティブにされますPolyspace as You Code 解析で非アクティブにされるチェッカー (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 を使用して、3 つの異なるスコープで 3 つの変数を宣言しています。これらの識別子は static であり、一意でない名前を共有するため、Polyspace は識別子の繰り返しにフラグを設定します。

チェック情報

グループ: 識別子
カテゴリ: 推奨
AGC カテゴリ: Readability

バージョン履歴

R2024a で導入


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.