MISRA C:2012 Rule 7.1
Octal constants shall not be used
Description
Rule Definition
Octal constants shall not be used1 .
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
#define CST 021 /* Noncompliant */
#if 010 == 01 /* Noncompliant*/
#define CST 021
#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 R2014b1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.
The MISRA coding standards referenced in the Polyspace Bug Finder™ documentation are from the following MISRA standards:
MISRA C:2004
MISRA C:2012
MISRA C:2023
MISRA C++:2008
MISRA C++:2023
MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.