Forward reference

From Wikipedia, the free encyclopedia

Some information in this article or section is not attributed to sources and may not be reliable.
Please check for inaccuracies, and modify and cite sources as needed.

In computer science, a forward reference refers to a program entity that precedes an entity's definition in a computer program.

While a language processor processes a statement containing a forward reference, it does not process all the information concerning the referenced entity. Instead, it postpones the generation of target code until more information concerning the entity becomes available. This may reduce the language processor's memory requirements and simplify its structure.

[edit] Example

Consider the following program code, to calculate profit:

profit = (profit * 100) / cost_price;

long profit;

The code "long profit" declares a variable, called profit, of type 'long'. The reference to profit in the preceding assignment statement constitutes a forward reference because profit's definition occurs after the assignment of its value.