![]() |
|
MISRA-C:2004 Rule 7.1: (Required) |
|
||||
![]() | |||||||
code[1]=109;/* equivalent to decimal 109 */code[2]=100;/* equivalent to decimal 100 */code[3]=052;/* equivalent to decimal 42 */code[4]=071;/* equivalent to decimal 57 */
Octal escape sequences can be problematic because the inadvertent introduction of a decimal digit ends the octal escape and introduces another character. The value of the first expression in the following example is implementation-defined because the character constant consists of two characters, '\10' and '9'. The second character constant expression below contains the single character '\100'. Its value will be implementation-defined if character 64 is not represented in the basic execution character set.
code[5]='\109';/* implementation-defined, two character constant */code[6]='\100';/* set to 64, or implementation-defined */
It is better not to use octal constants or escape sequences at all, and to statically check for any occurrences. The integer constant zero (written as a single numeric digit), is strictly speaking an octal constant, but is a permitted exception to this rule. Additionally "\0" is the only permitted octal escape sequence.
QAC messages that encompass this guideline:
| 0336 | Macro defined as an octal constant. |
| 0339 | Octal constant used. |
| 3628 | Octal escape sequences used in a character constant or string literal. |
|
||
(c) The Motor Industry Research Association, 2004
|
QA C Source Code Analyser 8.1.2
MISRA-C:2004 Compliance Module 3.2 © 2013 Programming Research www.programmingresearch.com |
Personality Groups | Glossary | Message Index | MISRA-C:2004 Rule Index | Contents |