MISRA C:2012 Dir 4.6
typedefs
that indicate size and signedness
should be used in place of the basic numerical types
Description
Directive Definition
typedefs
that indicate size and
signedness should be used in place of the basic numerical types1
.
Rationale
When the amount of memory being allocated is important, using a type that indicates its lengths makes it clear how much storage is being reserved for each object.
Polyspace Implementation
Polyspace® considers integer, float, and complex types as basic numeric types. A violation is reported if the data type for basic numeric types do not include a valid size in bits or contain commonly used size-related words. Valid sizes in bits are multiples of eight. Supported size-related words are bit, byte, word, and other common keywords.
Polyspace checks data types in function prototypes, type declarations, variable
declarations, cast expressions, and the sizeof
operator.
Polyspace does not report a violation on these uses:
Use of complex and imaginary types in cast conversions.
Use of the types
size_t
andptrdiff_t
.Use of plain
char
.Use of
int
as the return type of themain()
function.Use of
int
as the type for a parameter of themain()
function.Use of known boolean types such as
bool
or_Bool
.
The header stdint.h
defines some fixed width types
that represent the smallest or the fastest possible size of a type. Examples include
int_least8_t
, unit_fast_8_t
, and similar
types. See Fixed
with integer types. Polyspace reports a violation if you use these types. For example, this code
declares the 24bit variable var_globe24
as an integer that has at
least 8 bits.
int_least8_t var_glob24;
Troubleshooting
If you expect a rule violation but do not see it, refer to Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Code design |
Category: Advisory |
AGC Category: Advisory |
Version History
Introduced in R2014bSee Also
External Websites
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.