メインコンテンツ

MISRA C++:2008 Rule 5-0-11

The plain char type shall be used only for the storage and use of character values

説明

ルール定義

The plain char type shall be used only for the storage and use of character values 1

根拠

プレーンな char の符号属性は処理系定義です。符号が明確に定義されていないことから、プレーンの char 型は数値で使用するには適切ではありません。プレーンの char は、ストレージおよび文字値で使用してください。

Polyspace 実装

チェッカーは、符号付きまたは符号なし整数型の値が暗黙的にプレーンの char 型に変換されている場合に違反を報告します。

トラブルシューティング

ルール違反が想定されるものの、Polyspace® から報告されない場合は、コーディング規約違反が想定どおりに表示されない理由の診断を参照してください。

すべて展開する

#include<stdint.h>
typedef  char char_t;
void foo(){
char a = 'a'; // Compliant
char_t b = '\r'; // Compliant
char_t c = 10; // Noncompliant
char d = 'd'; // Compliant
}

この例では、Polyspace は数値データに対するプレーンの char の使用にフラグを設定します。

チェック情報

グループ: Expressions
カテゴリ: 必要

バージョン履歴

R2015a で導入


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.