Skip to main content

IAR Embedded Workbench for RISC-V 3.40

MISRAC2012-Rule-5.3_c89

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 31 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:

/*          1234567890123456789012345678901********* */
extern int  n01_param_hides_var__________31x;
extern int  n02_var_hides_var____________31x;
void        n03_var_hides_function_______31x (void) {}

enum E {
            n04_var_hides_enum_const_____31x,
};
#define     n05_var_hides_macro_name_____31x 123
extern int  n06_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_enum_const_____31y;
  int       n05_var_hides_macro_name_____31y;

  switch(f2()) {
  case 1: {
    typedef int n06_type_hides_var___________31y;
    do {
      /*     1234567890123456789012345678901********* */
      int n07_var_hides_var_______________31x;
      if(f3()) {
	int  n07_var_hides_var_______________31y = 1;
      }
    } while(f2());
  }
  }
}

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

int 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;
  }
  return 0;
}

/* identifiers in different name spaces */
/*          1234567890123456789012345678901********* */
union       n03_var_hides_union_tag______31x {
  int v1;
  unsigned int v2;
};
enum        n04_var_hides_enum_tag_______31x {
	    n05_tag_hides_enum_const_____31x
};
extern int  n06_label_hides_var__________31x;

int f2(void) {
  int       n03_var_hides_union_tag______31y;
  int       n04_var_hides_enum_tag_______31y;
  struct    n05_tag_hides_enum_const_____31y {
    int ff2;
  };
/*
 1234567890123456789012345678901********* */
 n06_label_hides_var__________31y:

  switch(f2()) {
  case 0: {
    do {
      /*     1234567890123456789012345678901********* */
      struct n07_var_hides_struct_tag_____31x {
	int ff1;
      };
      if(f3()) {
	int  n07_var_hides_struct_tag_____31y = 1;
      }
    } while(f2());
  }
  }
  return 0;
}