![]() |
|
MISRA-C:2004 Rule 5.1: (Required) |
|
||||
![]() | |||||||
The ISO standard requires external identifiers to be distinct in the first 6 characters, regardless of case, to guarantee optimal portability. However this limitation is particularly severe and is considered unnecessary. The intent of this rule is to sanction a relaxation of the ISO requirement to a degree commensurate with modern environments and it shall be confirmed that 31 character/case significance is supported by the implementation.
Note that there is a related issue with using identifier names that differ by only one or a few characters, especially if the identifier names are long. The problem is heightened if the differences are in easily mis-read characters like 1 (one) and l (lower case L), 0 and O, 2 and Z, 5 and S, or n and h. It is recommended to ensure that identifier names are always easily visually distinguishable. Specific guidelines on this issue could be placed in the style guidelines.
Example Code:
/* PRQA S 2985,3210, 3408, 3447 ++ */
#include "misra.h"
#include "m2cmex.h"
extern void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1( void ); /* 31 a's */
extern void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa2( void ); /* also 31 a's - MISRA Violation */
extern S16 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb1; /* 31 b's */
extern S16 bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb2; /* also 31 b's - MISRA Violation */
extern S16 cccccccccccccccccccccccccccccc1; /* 30 c's */
extern S16 cccccccccccccccccccccccccccccc2; /* also 30 c's - OK */
extern S16 test_0501( void )
{
S16 r;
S16 ddddddddddddddddddddddddddddddd1 = 1; /* 31 d's */
S16 ddddddddddddddddddddddddddddddd2 = 1; /* also 31 d's - MISRA Violation */
r = bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb1 +
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb2 +
cccccccccccccccccccccccccccccc1 +
cccccccccccccccccccccccccccccc2 +
ddddddddddddddddddddddddddddddd1 +
ddddddddddddddddddddddddddddddd2;
return r;
}
QAC messages that encompass this guideline:
| 0777 | [U] External identifier does not differ from other identifier(s) (e.g. '%s') within the specified number of significant characters. |
| 0779 | [U] Identifier does not differ from other identifier(s) (e.g. '%s') within the specified number of significant characters. |
Related rules:
| Rule 1.2 | No reliance shall be placed on undefined or unspecified behaviour. |
|
||
(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 |