Rule A13-6-1 (required, implementation, automated)
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 Language Standard it is allowed (optionally) to separate any two digits in digit sequences with separator ’. However, to meet developer expectations, usage of separator 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, 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 =
// Compliant
std::uint8_t binary2 = 0b10’00’10’01; // Non-compliant
}
See also
ISO 26262-6 [5]: 8.4.4 e) readability and comprehensibility