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.SIGNED_CHAR.NOT_NUMERIC

'signed char' or 'unsigned char' is used for non-numeric value.

MISRA-C Rule 6.2 (required): signed and unsigned char type shall be used only for the storage and use of numeric values.

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-12 (required): signed char and unsigned char type shall only be used for the storage and use of numeric values.

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

Rationale

There are three distinct char types, (plain) char, signed char and unsigned char. signed char and unsigned char shall only be used for numeric data and plain char shall only be used for character data. As it is implementation-defined, the signedness of the plain char type should not be assumed.

Note that Rule 3—9—2 also applies, so the 'uint8_t' and 'int8_t' types are covered by this rule.

Example

   int8_t   a = 'a';   // Non-compliant — explicitly signed
   uint8_t  b = '\r';  // Non-compliant — explicitly unsigned
   int8_t   c = 10;    // Compliant
   uint8_t  d = 12U;   // Compliant
signed char e = 11;    // Compliant with this rule, but breaks Rule 3—9—2