Redundant code

1

In computer programming, redundant code is source code or compiled code in a computer program that is unnecessary, such as: A NOP instruction might be considered to be redundant code that has been explicitly inserted to pad out the instruction stream or introduce a time delay, for example to create a timing loop by "wasting time". Identifiers that are declared, but never referenced, are termed redundant declarations.

Examples

The following examples are in C. The second expression is redundant code and can be replaced by a reference to the variable. Alternatively, the definition can instead be removed. Consider: As a consequence of using the C preprocessor, the compiler will only see the expanded form: Because the use of min/max macros is very common, modern compilers are programmed to recognize and eliminate redundancy caused by their use. There is no redundancy, however, in the following code: If the initial call to rand, modulo range, is greater than or equal to cutoff, rand will be called a second time for a second computation of rand%range, which may result in a value that is actually lower than the cutoff. The max macro thus may not produce the intended behavior for this function.

This article is derived from Wikipedia and licensed under CC BY-SA 4.0. View the original article.

Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc.
Bliptext is not affiliated with or endorsed by Wikipedia or the Wikimedia Foundation.

Edit article