Jump to content

Undefined value

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Incnis Mrsi (talk | contribs) at 22:32, 26 March 2010 (Created page with '{{otheruses|Undefined}} {{refimprove|date=March 2010}} In computing (particularly, in programming), '''undefined value (computer science)''' is a condition...'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

In computing (particularly, in programming), undefined value is a condition where an expression has not a correct value, although it is syntactically correct. Undefined value may not be confused with empty string, boolean "false" or other "empty" (but defined) values. Depending on circumstances, evaluation to undefined value may lead to exception or undefined behaviour, but in some programming languages undefined values can occur during a normal, predictable course of program execution.

Dynamically typed languages usually treat undefined values explicitly (when possible), e.g. Perl has undef operator[1] which can "assign" such value to a variable. In another type systems an undefined value may be unknown, unpredictable value, or merely a program failure on attempt of its evaluation.

Examples

Value of a partial function is undefined, when its argument is out of domain of definition. This include numerous arithmetical cases such as division by zero, square root or logarithm of a negative number etc.

Even some mathematically well-defined expressions like exp(100000) may be undefined in floating point arithmetic because exceed its limits.

Element of an array is undefined when index is out of bounds, as a lookup in an associative array for a key which it does not contain.

An argument of variadic function, which was not passed to it, is undefined when function is called.

A variable which is not initialized, has undefined (or unpredictable) value until it was assigned.

Any expression of the bottom type is undefined by definition, because that type has no values.

The value of a function which loops forever (for example, in the case of failed μ operator in a partial recursive function) may be seen as undefined too, but only of a theoretical interest because such function never returns.

Treatment

In Perl language, definedness of an expression can be checked via predicate defined(expr).[2] The use of undefined value in Perl is quite safe, it is equivalent to false in logical context (under if etc.).

In such statically typed languages as C(C++) there is no specific notion of runtime undefined value. Arithmetically undefined expressions invoke exceptions and crash the program, if uncaught. Undefined (means, unpredictable) data in C and similar languages may appear in case of flawy designed program or unexpected fault, and represent a severe danger, particularly pointers to deallocated memory and null pointers to arrays or structures. Even reading memory from a garbage pointer can crash a program.

Notation

In computability theory, undefinedness of an expression is denoted as expr↑, and definedness as expr↓.

See also