Jump to content

Redundant code

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Derek farn (talk | contribs) at 12:04, 21 October 2008 (Simplified introduction). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Redundant code is a computer programming term for code in a computer program that is redundant in some way. For instance, recomputing a value that has previously been calculated and is still available, or code that is never executed.

Redundant code elimination is a form of compiler optimization in which redundant computations are removed from a program. The redundant code elimination technique is in the same class of optimizations as unreachable code elimination and dead code elimination.

Example

 int f (int x)
 {
 	int y=x*2;
 	return x*2;
 }

The second x*2 expression is redundant code and can be replaced by a reference to the variable y. Alternatively the definition int y=x*2 can instead be removed.

Alternate uses of the term

Redundant code may also be used to refer to code that is executed but has no effect on the output of a program - however this is usually known as dead code. A NOP might be considered to be redundant code that has been explicitly inserted to pad out the instruction stream or introduce a time delay. Identifiers that are declared but never referenced are usually termed as redundant declarations. [citation needed]

See also

References