Main Content

AUTOSAR C++14 Rule A2-13-5

Hexadecimal constants should be uppercase

Description

Rule Definition

Hexadecimal constants should be uppercase.

Rationale

Hexadecimal notation uses digits 0–9 and letters A to F. Using only uppercase alphabetic letters in a hexadecimal constant definition helps keep the source code consistent, readable, and easy to maintain.

A mix of uppercase and lowercase hexadecimal constants might lead to confusion in the development process, which in turn might lead to bugs. Consistently enforcing the exclusive use of uppercase hexadecimal constants reduces this potential issue.

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

expand all

This example shows the Polyspace implementation of AUTOSAR rule A2-13-5.

#include <cstdint>

int main(void)
{
  std::int16_t a = 0x0f0f; //Noncompliant
  std::int16_t b = 0x0f0F; //Noncompliant
  std::int16_t c = 0x0F0F; //Compliant
  return 0;
}
 

In this example, three hexadecimal constants are defined. All three constants have the same value, but two of these definitions use lowercase letters. Because the definitions of the hexadecimal constants a and b do not use uppercase letters exclusively, Polyspace flags their definitions as noncompliant with this rule. Because the definition of the hexadecimal constant c uses uppercase letters exclusively, Polyspace does not flag its definition as noncompliant with this rule.

Check Information

Group: Lexical Conventions
Category: Advisory, Automated

Version History

Introduced in R2019a