Variables declared and never used in a project constitute noise and may indicate that the wrong variable name has been used somewhere. Removing these declarations reduces the possibility that they may later be used instead of the correct variable.
If padding is used within bit-fields, then the padding members should be unnamed to avoid violation of this rule.
== Noncompliant Code Example
----
extern void usefn ( int16_t a, int16_t b );
class C
{
// ...
};
C c; // Non-compliant - unused
void withunusedvar ( void )
int16_t unusedvar; // Noncompliant – unused
struct s_tag
signed int a : 3;
signed int pad : 1; // Noncompliant – should be unnamed
signed int b : 2;
} s_var;
s_var.a = 0;
s_var.b = 0;
usefn ( s_var.a, s_var.b );
}
== See
* MISRA {cpp}:2008, 0-1-3