AUTOSAR C++14 Rule A13-6-1
Digit sequences separators ' shall only be used as follows: (1) for decimal, every 3 digits, (2) for hexadecimal, every 2 digits, (3) for binary, every 4 digits
Since R2021a
Description
Rule Definition
Digit sequences separators ' shall only be used as follows: (1) for decimal, every 3 digits, (2) for hexadecimal, every 2 digits, (3) for binary, every 4 digits.
Rationale
Since C++14, you can introduce a separator '
to separate digits in a
digit sequence for better readability. For consistency across your code, follow this
convention when entering the digit sequence separator:
In decimal values, starting from the right, place the separator after every three digits, for instance,
3'000'000
.In hexadecimal values, starting from the right, place the separator after every two digits, for instance,
0xF'FF'0F
.In binary values, starting from the right, place the separator after every four digits, for instance,
0b1001'0011'0100
.
If you are consistent across your code, a developer or code reviewer can follow your code more easily and possibly estimate the order of magnitude of a value from the digit sequence separators.
Polyspace Implementation
This checker follows the specifications of the AUTOSAR C++14 rule.
For integers, the checker starts checking from the right. For instance, the checker
raises a violation on the value 45'30'00
, because starting from the
right, the digit sequence separator appears after two digits instead of the expected
three.
For floating-point numbers, the checker begins the check from the decimal point and proceeds outwards. The checker checks:
The part before the decimal starting from the right.
The part after the decimal starting from the left.
For floating-point numbers with a mantissa and exponent, the same rule as integers applies to the exponent. For instance, in the decimal notation, the checker checks exponents starting from the right and raises a violation if the digit sequence separators are placed, for instance, after every two digits instead of three.
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: Overloading |
Category: Required, Automated |
Version History
Introduced in R2021a