Jump to content

Unreferenced variable: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Rollback edit(s) by 81.174.231.169 (talk) to rev. 956147121 by DannyS712 bot: vandalism (RedWarn rev12)
No edit summary
Line 1: Line 1:
{{Unreferenced|date=February 2007}}
{{Lead missing |date=February 2020}}
An '''unreferenced variable''' in the [[source code]] of a [[computer program]] is a [[Variable (programming)|variable]] that is defined but which is never used. This may result in a harmless waste of memory. Many [[compiler]]s detect such variables and do not allocate storage for them (i.e., "optimize away" their storage), generally also issuing a warning as they do.
An '''unreferenced tubby''' in the [[source code]] of a [[computer program]] is a [[Variable (programming)|variable]] that is defined but which is never used. This may result in a harmless waste of memory. Many [[compiler]]s detect such variables and do not allocate storage for them (i.e., "optimize away" their storage), generally also issuing a warning as they do.


Some [[coding style|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.
Some [[coding style|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.

Revision as of 10:36, 9 June 2020

An unreferenced tubby 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.

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

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.