Redundant code
Encyclopedia
Redundant code is a computer programming
Computer programming
Computer programming is the process of designing, writing, testing, debugging, and maintaining the source code of computer programs. This source code is written in one or more programming languages. The purpose of programming is to create a program that performs specific operations or exhibits a...

 term for code, which may be source code
Source code
In computer science, source code is text written using the format and syntax of the programming language that it is being written in. Such a language is specially designed to facilitate the work of computer programmers, who specify the actions to be performed by a computer mostly by writing source...

 or compiled code in a computer program
Computer program
A computer program is a sequence of instructions written to perform a specified task with a computer. A computer requires programs to function, typically executing the program's instructions in a central processor. The program has an executable form that the computer can use directly to execute...

, that has any form of redundancy, such as recomputing a value that has previously been calculated and is still available, code that is never executed (often called unreachable code
Unreachable code
Unreachable code is a computer programming term for code in the source code of a program which can never be executed because there exists no control flow path to the code from the rest of the program....

), or code which is executed but has no external effect (e.g., does not change the output produced by a program), usually known as dead code
Dead code
Dead code is a computer programming term for code in the source code of a program which is executed but whose result is never used in any other computation...

.

A NOP
NOP
In computer science, NOP or NOOP is an assembly language instruction, sequence of programming language statements, or computer protocol command that effectively does nothing at all....

 instruction might be considered to be redundant code that has been explicitly inserted to pad out the instruction stream or introduce a time delay. Identifier
Identifier
An identifier is a name that identifies either a unique object or a unique class of objects, where the "object" or class may be an idea, physical [countable] object , or physical [noncountable] substance...

s that are declared, but never referenced, are usually termed as redundant declarations. However, in some cases, a NOP can be used to create timing loops by "wasting time".

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.
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK