Skip to main content

IAR Embedded Workbench for RL78 5.20

RED-local-hides-param

In this section:
Synopsis

A variable declaration hides a parameter of the function

Enabled by default

Yes

Severity/Certainty

Medium/Medium

mediummedium.png
Full description

A local variable is declared in a function with the same name as an argument of the function, hiding the argument from this scope, from this point onwards. This might be intentional, but it is better to use a different name for the variable, so that a reference to the argument does not accidentally change or return the inner value.

Coding standards
CERT DCL01-C

Do not reuse variable names in subscopes

CERT DCL01-CPP

Do not reuse variable names in subscopes

Code examples

The following code example fails the check and will give a warning:

int foo(int x) {
  for (int x = 0; x < 100; x++);
  return x;
}

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

int foo(int x) {
  int y;
  return x;
}