rspec/rules/S801/rule.adoc

36 lines
807 B
Plaintext

== Why is this an issue?
When a variable in a nested scope has the same name as one in an outer scope, it hides the outer scope's variable, which can no longer be accessed in the inner scope. Thus all uses of that variable name in the inner scope will reference the variable declared in the inner scope. However, that may not be clear to everyone. particularly in large code blocks. Therefore identifiers in inner scopes should never hide those from outer scopes.
=== Noncompliant code example
[source,text]
----
void fn1 ( void )
{
int16_t i;
{
int8_t i; /* Non-compliant - hides previous "i " */
i = 3; /* Could be confusing as to which "i" this is */
}
}
----
=== Compliant solution
[source,text]
----
void fn1 ( void )
{
int16_t i;
{
int8_t j;
j = 3;
}
}
----