MISRAC2012-Rule-5.2_c99
In this section:
Synopsis
(Required) Identifiers declared in the same scope and name space shall be distinct.
Enabled by default
Yes
Severity/Certainty
Low/Medium

Full description
Identifier names were found that are not distinct in their first 63 characters from other names in the same scope.
Coding standards
- MISRA C:2012 Rule-5.2
(Required) Identifiers declared in the same scope and name space shall be distinct
Code examples
The following code example fails the check and will give a warning:
/* 0 1 2 3 4 5 6 */
/* 123456789012345678901234567890123456789012345678901234567890123* */
extern int n01_var_hides_var____________________________________________63x;
static int n01_var_hides_var____________________________________________63y;
/* 0 1 2 3 4 5 6 */
/* 123456789012345678901234567890123456789012345678901234567890123* */
static int n02_function_hides_var_______________________________________63x;
void n02_function_hides_var_______________________________________63y (void) {}
void foo(void) {
int i;
switch(f1()) {
case 1: {
do {
for(i = 0; i < 10; i++) {
if(f3()) {
/* 0 1 2 3 4 5 6 */
/* 123456789012345678901234567890123456789012345678901234567890123* */
int n03_var_hides_var____________________________________________63x;
int n03_var_hides_var____________________________________________63y;
}
}
} while(f2());
}
}
}
/* 0 1 2 3 4 5 6 */
/* 123456789012345678901234567890123456789012345678901234567890123* */
enum E {
n04_var_hides_enum_const_____________________________________63x
};
/* 0 1 2 3 4 5 6 */
/* 123456789012345678901234567890123456789012345678901234567890123* */
int n04_var_hides_enum_const_____________________________________63y;
/* 0 1 2 3 4 5 6 */
/* 123456789012345678901234567890123456789012345678901234567890123* */
void bar(int n05_var_hides_parameter______________________________________63x) {
int n05_var_hides_parameter______________________________________63y;
}
/* 0 1 2 3 4 5 6 */
/* 123456789012345678901234567890123456789012345678901234567890123* */
#define n06_var_hides_macro_name_____________________________________63x 123
int n06_var_hides_macro_name_____________________________________63y;
/* 0 1 2 3 4 5 6 */
/* 123456789012345678901234567890123456789012345678901234567890123* */
int n07_type_hides_var___________________________________________63x;
typedef int n07_type_hides_var___________________________________________63y;
/* 0 1 2 3 4 5 6 */
/* 123456789012345678901234567890123456789012345678901234567890123* */
union U {
int n08_field_hides_field________________________________________63x;
int n08_field_hides_field________________________________________63y;
};
struct S {
int n09_field_hides_field________________________________________63x;
int n09_field_hides_field________________________________________63y;
};
The following code example passes the check and will not give a warning about this issue:
/* 0 1 2 3 4 5 6 */
/* 123456789012345678901234567890123456789012345678901234567890123********* */
extern int n01_var_in_different_scope___________________________________63x;
void n02_different_function_name__________________________________63x (void) {
static int n01_var_in_different_scope___________________________________63y;
switch(fn()) {
case 1:
{
int n01_var_in_different_scope___________________________________63a;
}
break;
case 2:
{
int n01_var_in_different_scope___________________________________63b;
}
break;
}
{
int n01_var_in_different_scope___________________________________63c;
}
{
int n01_var_in_different_scope___________________________________63d;
}
}
/* 0 1 2 3 4 5 6 */
/* 123456789012345678901234567890123456789012345678901234567890123* */
void n12_var_hides_function_different_scope_______________________63x (void) {
static int n12_var_hides_function_different_scope_______________________63y;
}
/* exception for typedef of tag name*/
typedef struct s1 {
int sf1;
} s1;
typedef union u1 {
int uf1;
int uf2;
} u1;
typedef enum e1 {
ec1, ec2
} e1;
/* identifiers in different name spaces */
void foo(void) {
int i;
switch(f1()) {
case 1: {
do {
for(i = 0; i < 10; i++) {
if(f3()) {
/* 0 1 2 3 4 5 6 */
/* 123456789012345678901234567890123456789012345678901234567890123* */
struct n03_var_hides_struct_tag_____________________________________63x {
int f1;
} n03_var_hides_struct_tag_____________________________________63y;
}
}
} while(f2());
}
}
}
/* 0 1 2 3 4 5 6 */
/* 123456789012345678901234567890123456789012345678901234567890123* */
union n04_var_hides_union_tag______________________________________63x {
int v1;
unsigned int v2;
} n04_var_hides_union_tag______________________________________63y;
/* 0 1 2 3 4 5 6 */
/* 123456789012345678901234567890123456789012345678901234567890123* */
enum n05_var_hides_enum_tag_______________________________________63x {
n07_tag_hides_enum_const_____________________________________63x
};
/* 0 1 2 3 4 5 6 */
/* 123456789012345678901234567890123456789012345678901234567890123* */
int n05_var_hides_enum_tag_______________________________________63y;
struct
n07_tag_hides_enum_const_____________________________________63y {
int sf2;
};
void bar(void) {
/* 0 1 2 3 4 5 6 */
/* 123456789012345678901234567890123456789012345678901234567890123* */
int n09_label_hides_var__________________________________________63x;
{
/*0 1 2 3 4 5 6 */
/*123456789012345678901234567890123456789012345678901234567890123* */
n09_label_hides_var__________________________________________63y:
n09_label_hides_var__________________________________________63x = 1;
}
}