What about unused variables?

Moderators: misra-c, david ward

Post Reply
Posts: 8
Joined: Wed May 28, 2014 6:53 pm
Company: GrammaTech Inc.

What about unused variables?

Post by swestin » Fri Jul 18, 2014 2:51 pm

The guidelines proscribe declaring unused types, tags on structures or enums, macros, or labels.

Shouldn't there be a prohibition of undeclared variables, too?

-Stephen H. Westin

Posts: 571
Joined: Thu Jan 05, 2006 1:11 pm

Re: What about unused variables?

Post by misra-c » Fri Aug 22, 2014 12:30 pm

We are assuming that the question is intended to read "Shouldn't there be a prohibition of unused variables, too?"

Rule 2.7 covers variables that are declared as parameters to functions.

MISRA C:2012 permits other variables to be initialised and not used. However, if a variable is assigned a value, which is not used, then dead code will exist and rule 2.2 will be violated.

Unused initialisations are permitted because a common programming style is to use configuration files and conditional compilation. This can lead in some configurations to some variables being initialised but never used.
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “8.2 Unused code”