Main Content
MISRA C:2023 Rule 7.1
Octal constants shall not be used
Since R2024a
Description
Rule Definition
Octal constants shall not be used.
Rationale
Octal constants are denoted by a leading zero. Developers can mistake an octal constant as a decimal constant with a redundant leading zero.
Polyspace Implementation
If you use octal constants in a macro definition, the rule checker flags the issue even if the macro is not used.
Troubleshooting
If you expect a rule violation but do not see it, refer to Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Example - Use of octal constants
#define CST 021 /* Noncompliant */ #define VALUE 010 /* Noncompliant */ #if 010 == 01 /* Noncompliant*/ #define CST 021 /* Noncompliant */ #endif extern short code[5]; static char* str2 = "abcd\0efg"; /* Compliant */ void main(void) { int value1 = 0; /* Compliant */ int value2 = 01; /* Noncompliant*/ int value3 = 1; /* Compliant */ int value4 = '\109'; /* Compliant */ code[1] = 109; /* Compliant - decimal 109 */ code[2] = 100; /* Compliant - decimal 100 */ code[3] = 052; /* Noncompliant */ code[4] = 071; /* Noncompliant */ if (value1 != CST) { value1 = !(value1 != 0); /* Compliant */ } }
In this example, Polyspace® flags the use of octal constants.
Check Information
Group: Literals and Constants |
Category: Required |
AGC Category: Advisory |
Version History
Introduced in R2024a