MISRAC2004-5.2
In this section:
Synopsis
(Required) Identifiers in an inner scope shall not use the same name as an identifier in an outer scope, and thus hide that identifier.
Enabled by default
Yes
Severity/Certainty
Low/Medium

Full description
An identifier name was found that is not distinct in the first 31 characters from other names in an outer scope.
Coding standards
- MISRA C:2004 5.2
(Required) Identifiers in an inner scope shall not use the same name as an identifier in an outer scope, and therefore hide that identifier.
Code examples
The following code example fails the check and will give a warning:
/* 1234567890123456789012345678901********* */
extern int n01_param_hides_var__________31x;
extern int n02_var_hides_var____________31x;
void n03_var_hides_function_______31x (void) {}
union n04_var_hides_union_tag______31x {
int v1;
unsigned int v2;
};
enum n05_var_hides_enum_tag_______31x {
n06_var_hides_enum_const_____31x,
n07_tag_hides_enum_const_____31x
};
#define n08_var_hides_macro_name_____31x 123
extern int n09_label_hides_var__________31x;
extern int n10_type_hides_var___________31x;
void f1(int n01_param_hides_var__________31y) {
int n02_var_hides_var____________31y;
int n03_var_hides_function_______31y;
int n04_var_hides_union_tag______31y;
int n05_var_hides_enum_tag_______31y;
int n06_var_hides_enum_const_____31y;
struct n07_tag_hides_enum_const_____31y {
int ff2;
};
int n08_var_hides_macro_name_____31y;
/*
1234567890123456789012345678901********* */
n09_label_hides_var__________31y:
switch(f2()) {
case 1: {
typedef int n10_type_hides_var___________31y;
do {
/* 1234567890123456789012345678901********* */
struct n11_var_hides_struct_tag_____31x {
int ff1;
};
if(f3()) {
int n11_var_hides_struct_tag_____31y = 1;
}
} while(f2());
}
}
}
The following code example passes the check and will not give a warning about this issue:
void f1 (void) {
/* 1234567890123456789012345678901********* */
extern int n01_var_in_same_scope________31x;
static int n01_var_in_same_scope________31y;
switch(fn()) {
case 1:
{
int n02_var_in_different_scope___31a;
}
break;
case 2:
{
int n02_var_in_different_scope___31b;
}
break;
}
{
int n02_var_in_different_scope___31c;
}
{
int n02_var_in_different_scope___31d;
}
}