Main Content

MISRA C++:2023 Rule 5.13.3

Octal constants shall not be used

Since R2024b

Description

Rule Definition

Octal constants shall not be used.

Rationale

Octal constants are denoted by a leading zero. You can confuse an octal constant as a decimal constant with a redundant leading zero.

Octal escape sequences beginning with \ are compliant.

Polyspace Implementation

The rule checker reports violations on constants beginning with a leading zero.

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

The checker flags all octal constants (other than zero).

In this example:

  • The octal escape sequence contains the digit 9, which is not an octal digit. This escape sequence has implementation-defined behavior.

  • The octal escape sequence \100 represents the number 64, but is compliant with this rule.

void func(void) {
  int busData[6];
  
  busData[0] = 100;
  busData[1] = 108;
  busData[2] = 052;      //Noncompliant
  busData[3] = 071;      //Noncompliant
  busData[4] = '\109';   //Compliant
  busData[5] = '\100';   //Compliant

}

Check Information

Group: Lexical Conventions
Category: Required

Version History

Introduced in R2024b