Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

MISRA.CHAR.NOT_CHARACTER

'char' is used for non-character value.

MISRA-C Rule 6.1 (required): The plain char type shall be used only for the storage and use of character values.

[Implementation 14]

There are three distinct char types, (plain) char, signed char and unsigned char. signed char and unsigned char shall be used for numeric data and plain char shall be used for character data. The signedness of the plain char type is implementation defined and should not be relied upon.

Character values/data are character constants or string literals such as 'A', '5', '\n', "a".

Numeric values/data are numbers such as 0, 5, 23, \x10, -3.

Character sets map text characters onto numeric values. Character values are the "text".

The permissible operators on plain char types are the simple assignment operator (=), equality operators (==, !=) and explicit casts to integral types. Additionally, the second and third operands of the ternary conditional operator may both be of plain char type.

MISRA-C++ Rule 5-0-11 (required): The plain char type shall only be used for the storage and use of character values.

[Implementation 3.9.1(1), 7.1.5.2(1)]

Rationale

The char type within C++ is defined for use with the implementation character set. It is implementation-defined if char is signed or unsigned, and it is therefore unsuitable for use with numeric data.

Character values consist of character literals or strings. A character set maps text characters onto numeric values; the character value is the text itself.

Note that Rule 3—9—2 applies, so this rule also covers the char_t type.

Example

char_t a = 'a';       // Compliant
char_t      b = '\r'; // Compliant
char_t      c = 10;   // Non-compliant
char        d = 'd';  // Compliant with this rule, but breaks Rule 3—9—2