Jump to content

Unreferenced variable

From Wikipedia, the free encyclopedia
This is the current revision of this page, as edited by Citation bot (talk | contribs) at 19:32, 22 February 2023 (Alter: url. URLs might have been anonymized. Add: authors 1-1. Removed parameters. Some additions/deletions were parameter name changes. | Use this bot. Report bugs. | Suggested by AManWithNoPlan | #UCB_CommandLine). The present address (URL) is a permanent link to this version.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

An unreferenced variable in the source code of a computer program is a variable that is defined but which is never used. This may result in a harmless waste of memory. Many compilers detect such variables and do not allocate storage for them (i.e., "optimize away" their storage), generally also issuing a warning as they do.[1]

Some coding guideline documents consider an unreferenced variable to be a symptom of a potential coding fault. On the other hand, unreferenced variables can be used as temporary placeholders to indicate further expected future developments in the code.

Examples

[edit]

C:

 int main(void)
 {
   int i, j;
   for (i=0; i<10; i++)
      printf("%d", i);
   return 0;
 }

In this example, j is an unreferenced variable.

References

[edit]
  1. ^ Blair-Chappell, Stephen; Stokes, Andrew (2012-04-19). Parallel Programming with Intel Parallel Studio XE. John Wiley & Sons. p. 108. ISBN 978-1-118-23488-4.