Skip to main content

IAR Embedded Workbench for RISC-V 3.40

MISRAC2012-Rule-5.3_c99

In this section:
Synopsis

(Required) An identifier declared in an inner scope shall not hide an identifier declared in an outer scope.

Enabled by default

Yes

Severity/Certainty

Low/Medium

lowmedium.png
Full description

Identifier names were found that are not distinct in their first 63 characters from other names in an outer scope.

Coding standards
MISRA C:2012 Rule-5.3

(Required) An identifier declared in an inner scope shall not hide an identifier declared in an outer scope

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_param_hides_var__________________________________________63x;
extern int  n02_var_hides_var____________________________________________63x;
void        n03_var_hides_function_______________________________________63x (void) {}

enum E {
            n04_var_hides_enum_const_____________________________________63x
};
#define     n05_var_hides_macro_name_____________________________________63x 123
extern int  n06_type_hides_var___________________________________________63x;

void f1(int n01_param_hides_var__________________________________________63y) {
  int       n02_var_hides_var____________________________________________63y;
  int       n03_var_hides_function_______________________________________63y;
  int       n04_var_hides_enum_const_____________________________________63y;
  int       n05_var_hides_macro_name_____________________________________63y;

  switch(f2()) {
  case 1: {
/*              0        1         2         3         4         5         6     */
/*              123456789012345678901234567890123456789012345678901234567890123* */
    typedef int n06_type_hides_var___________________________________________63y;
    do {
      int       n07_var_var__________________________________________________63x;
      if(f3()) {
	int     n07_var_var__________________________________________________63y = 1;
      }
    } while(f2());
  }
  }
}

The following code example passes the check and will not give a warning about this issue:

int f1 (void) {
/*           0        1         2         3         4         5         6     */
/*           123456789012345678901234567890123456789012345678901234567890123* */
  extern int n01_var_in_same_scope________________________________________63x;
  static int n01_var_in_same_scope________________________________________63y;

  switch(fn()) {
  case 1:
    {
      int    n02_var_in_different_scope___________________________________63a;
    }
    break;
  case 2:
    {
      int    n02_var_in_different_scope___________________________________63b;
    }
    break;
  }
  {
      int    n02_var_in_different_scope___________________________________63c;
  }
  {
      int    n02_var_in_different_scope___________________________________63d;
  }
  return 1;
}

/* identifiers in different name spaces */
/*          0        1         2         3         4         5         6     */
/*          123456789012345678901234567890123456789012345678901234567890123* */
union       n03_var_hides_union_tag______________________________________63x {
  int v1;
  unsigned int v2;
};
enum        n04_var_hides_enum_tag_______________________________________63x {
	    n05_tag_hides_enum_const_____________________________________63x
};
extern int  n06_label_hides_var__________________________________________63x;

int f2(void) {
  int       n03_var_hides_union_tag______________________________________63y;
  int       n04_var_hides_enum_tag_______________________________________63y;
  struct    n05_tag_hides_enum_const_____________________________________63y {
    int ff2;
  };
/*
 0        1         2         3         4         5         6
 123456789012345678901234567890123456789012345678901234567890123* */
 n06_label_hides_var__________________________________________63y:

  switch(f2()) {
  case 1: {
/*              0        1         2         3         4         5         6     */
/*              123456789012345678901234567890123456789012345678901234567890123* */
    do {
      struct    n07_var_hides_struct_tag_____________________________________63x {
	int ff1;
      };
      if(f3()) {
	int     n07_var_hides_struct_tag_____________________________________63y = 1;
      }
    } while(f2());
  }
  }
  return 0;
}