AutosarC++18_10-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
Required inputs: IR
| Level | required |
|---|---|
| Target | implementation |
| Enforcement | automated |
Rationale
Since C++14 Language Standard it is allowed (optionally) to separate any two digits indigit sequences with separator ’. However, to meet developer expectations, usage ofseparator in integer and floating-point digit sequences should be unified:
- for decimal values, separator can be placed every 3 digits, e.g. 3’000’000,3.141’592’653
- for hexadecimal values, separator can be placed every 2 digits, e.g. 0xFF’FF’FF’FF
- for binary values, separator can be placed very 4 digits, e.g. 0b1001’1101’0010
Example
// $Id: A13-6-1.cpp 289436 2017-10-04 10:45:23Z michal.szczepankiewicz $
#include <cstdint>
void Fn() noexcept
{
std::uint32_t decimal1 = 3’000’000; // Compliant
std::uint32_t decimal2 = 4’500; // Compliant
std::uint32_t decimal3 = 54’00’30; // Non-compliant
float decimal4 = 3.141’592’653; // Compliant
float decimal5 = 3.1’4159’265’3; // Non-compliant
std::uint32_t hex1 = 0xFF’FF’FF’FF; // Compliant
std::uint32_t hex2 = 0xFAB’1’FFFFF; // Non-compliant
std::uint8_t binary1 = 0b1001’0011; // Compliant
std::uint8_t binary2 = 0b10’00’10’01; // Non-compliant
}
See Also
- ISO 26262-6 [5]: 8.4.4 e) readability and comprehensibility
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
digit_separator |
Possibly unreadable digit separators. |
None |
False |
Options¶
This rule shares the following common options: confidence, exclude_in_macros, exclude_messages_in_system_headers, excludes, extend_exclude_to_macro_invocations, includes, justification_checker, languages, post_processing, provider, report_at, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
num_binary_digits¶
num_binary_digits : int = 4
num_decimal_digits¶
num_decimal_digits : int = 3
num_hex_digits¶
num_hex_digits : int = 2