Undefined variable

Undefined variable

An undefined variable in the source code of a computer program is a variable that is accessed in the code but has not been previously declared by that code.

In some programming languages an implicit declaration is provided the first time such a variable is encountered at compile time or run time error. In other languages such a usage is considered to be a fatal error, resulting an a diagnostic being issued.

Some languages have started out with the implicit declaration behavior but as they matured they provided an option to disable it (e.g. Perl's "use strict" or Visual Basic's "Option Explicit").

Examples

Examples of how various programming languages respond to undefined variables are given below. Each code example is followed by an error message (if any).

CLISP (GNU CLISP 2.35):(setf y x) *** - EVAL: variable X has no value

C (GNU GCC 3.4):int main() { int y = x; return 0;} foo.c: In function `main': foo.c:2: error: `x' undeclared (first use in this function) foo.c:2: error: (Each undeclared identifier is reported only once foo.c:2: error: for each function it appears in.)

JavaScript (Mozilla Firefox 1.0):

y = x Error: x is not defined Source File: file:///c:/temp/foo.js

ML (Standard ML of New Jersey v110.55):

val y = x; stdIn:1.9 Error: unbound variable or constructor: x

MUMPS

Set Y=X

OCaml 3.08let y = x;; Unbound value x

Perl 5.8:my $y = $x;(no error)

use strict;my $y = $x; Global symbol "$x" requires explicit package name at foo.pl line 2. Execution of foo.pl aborted due to compilation errors.

Python 2.4:x = y Traceback (most recent call last): File "foo.py", line 1, in ? x = y NameError: name 'y' is not defined

Ruby 1.8y = x NameError: undefined local variable or method `x' for main:Object from (irb):1

VBScript (WSH 5.6)Dim yy = x(no error)

Option Explicit

Dim yy = x (3, 1) Microsoft VBScript runtime error: Variable is undefined: 'x'


Wikimedia Foundation. 2010.

Игры ⚽ Нужна курсовая?

Look at other dictionaries:

  • undefined variable — neapibrėžtas kintamasis statusas T sritis informatika apibrėžtis ↑Kintamasis, kurio reikšmė neapibrėžta. Kai programa pradedama vykdyti, pirmiausia joje aprašytiems kintamiesiems paskiriama vieta atmintyje. O toje vietoje gali būti anksčiau ją… …   Enciklopedinis kompiuterijos žodynas

  • Variable — A variable (pronEng|ˈvɛərɪəbl) is an attribute of a physical or an abstract system which may change its value while it is under observation. Examples include the height of a child, the temperature across a state, or the input to a function. This… …   Wikipedia

  • Variable-Data Intelligent PostScript Printware — ist eine Seitenbeschreibungssprache, die von Xerox entwickelt wurde. Die Sprache basiert auf PostScript und ermöglicht die Trennung zwischen variablen und fixen Bestandteilen einer zu druckenden Seite. Der Vorteil besteht in einem geringeren… …   Deutsch Wikipedia

  • Undefined behavior — In computer programming, undefined behavior is a feature of some programming languages most famously C.[1] In these languages, to simplify the specification and allow some flexibility in implementation, the specification leaves the results of… …   Wikipedia

  • Automatic variable — In the C programming language= Variables declared within a block of code are, by default, automatic variables. This means that when the block is entered during program execution, the automatic variables will be automatically allocated; when the… …   Wikipedia

  • Declaration (computer programming) — In programming languages, a declaration specifies the identifier, type, and other aspects of language elements such as variables and functions. It is used to announce the existence of the element to the compiler; this is important in many… …   Wikipedia

  • Autovivification — is a unique feature of the Perl programming language involving the dynamic creation of data structures. Autovivification is the automatic creation of a reference when an undefined value is dereferenced. In effect, this causes access to an element …   Wikipedia

  • WATFIV (programming language) — WATFIV, or WATerloo FORTRAN IV, developed at the University of Waterloo, Canada is an implementation of Fortran IV. It is the successor of WATFOR.WATFIV was in turn succeeded by later versions of WATFOR. WATFIV was used from the late 1960s into… …   Wikipedia

  • Reference electrode — Reference electrodeis an electrode which has a stable and well known electrode potential.The high stability of the electrode potential is usually reached by employing a redox system with constant (buffered or saturated) concentrations of each… …   Wikipedia

  • open sentence — noun : a statement (as in mathematics) that contains at least one blank or unknown and that becomes true or false when the blank is filled or a quantity is substituted for the unknown * * * 1. Math. an equation or inequality containing one or… …   Useful english dictionary

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”