MISRA C++:2023 Rule 6.9.2
The names of the standard signed integer types and standard unsigned integer types should not be used
Since R2024b
Description
Rule Definition
The names of the standard signed integer types and standard unsigned integer types should not be used.
Rationale
The storage required for standard signed integer types and standard unsigned standard
types is implementation-dependent. The standard signed and unsigned integer types
include names of integral types constructed using the keywords char
,
short
, int
, long
,
singed
, and unsinged
. Using these types can
result in ambiguity regarding the amount of storage required. This rule does not apply
to the use of plain char
.
Using types with specific widths unambiguously determines the required storage. Use
the standard library header cstdint
, which typically provides a
suitable set of specific-width integer types. Alternatively, you can define your own
specific-width aliases. When defining your own type aliases, best practice is to
validate the sizes of these aliased types by using
static_assert
:
using uint8_t = unsigned char; static_assert(sizeof(uint8_t) == 1);
Using specific-width integer types does not prevent integer promotion. For example,
an integer of type int16_t
is promoted if the aliased type of
int16_t
has a rank lower than int
.
As exceptions, the standard signed or unsigned integer types do not violate this rule
when used in alias statements such as typedef
or
using
statements. The type name int
is also
allowed as:
The parameter to a postfix operator
The return type of
main()
The
argc
parameter tomain()
Polyspace Implementation
This rule checker reports a violation of this rule if the code uses standard signed
or unsigned integer type names constructed using the keywords char
,
short
, int
, long
,
singed
, and unsinged
. As exceptions, violations
are not reported when standard signed or unsigned integer type names are used in:
The
main()
function definitionPostfix operator parameters
typedef
orusing
statements
Troubleshooting
If you expect a rule violation but Polyspace® does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Basic Concepts |
Category: Advisory |
Version History
Introduced in R2024b