48 lines
1.3 KiB
Plaintext
48 lines
1.3 KiB
Plaintext
Ideally, identifiers (names of classes, variables, methods, structures, macros, labeles, &etc.) are all easily distinguished from one another. Unfortunately, some characters or combinations of characters look enough alike that that's not always the case.
|
|
|
|
|
|
Therefore, identifiers that differ from each other only by one of these problematic characters (or character combinations) should be renamed.
|
|
|
|
|
|
The problem pairs are:
|
|
|
|
* capital 'O' and digit 0
|
|
* capital 'I' (eye) and digit 1
|
|
* capital 'I' (eye) and lowercase 'l' (el)
|
|
* lowercase 'l' (el) and digit 1
|
|
* capital 'S' and digit 5
|
|
* capital 'Z' and digit 2
|
|
* lowercase 'n' and lowercase 'h'
|
|
* capital 'B' and digit 8
|
|
* lowercase 'm' and the combination "rn" ('r' followed by 'n')
|
|
* any lowercase letter and its uppercase variant
|
|
* the presence or absence of an underscore
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
----
|
|
int myl;
|
|
int myI;
|
|
int my1;
|
|
----
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
----
|
|
int my_el;
|
|
int my_upper_i;
|
|
int my_one;
|
|
----
|
|
|
|
|
|
== See
|
|
|
|
* MISRA {cpp}:2008, 2-10-1
|
|
* MISRA C:2012, Dir 4.5
|
|
* https://wiki.sei.cmu.edu/confluence/x/7DZGBQ[CERT, DCL50-J.] - Use visually distinct identifiers
|
|
* https://wiki.sei.cmu.edu/confluence/x/F9cxBQ[CERT, DCL02-C.] - Use visually distinct identifiers
|
|
* https://wiki.sei.cmu.edu/confluence/x/cdYxBQ[CERT, DCL16-C.] - Use "L," not "l," to indicate a long value
|
|
|