In
computer science
Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to Applied science, practical discipli ...
and
software programming
Computer programming is the process of performing a particular computation (or more generally, accomplishing a specific computing result), usually by designing and building an executable computer program. Programming involves tasks such as anal ...
, a value is the representation of some entity that can be manipulated by a program. The members of a
type are the values of that type.
The "value of a variable" is given by the corresponding
mapping in the
environment
Environment most often refers to:
__NOTOC__
* Natural environment, all living and non-living things occurring naturally
* Biophysical environment, the physical and biological factors along with their chemical interactions that affect an organism or ...
. In languages with
assignable variables, it becomes necessary to distinguish between the ''r-value'' (or contents) and the ''l-value'' (or location) of a variable.
In
declarative (high-level) languages, values have to be
referentially transparent
In computer science, referential transparency and referential opacity are properties of parts of computer programs. An expression is called ''referentially transparent'' if it can be replaced with its corresponding value (and vice-versa) withou ...
. This means that the resulting value is independent of the location of the expression needed to compute the value. Only the contents of the location (the bits, whether they are 1 or 0) and their interpretation are significant.
Value category
Despite its name, in the C++ language standards this terminology is used to categorize expressions, not values.
Assignment: l-values and r-values
Some languages use the idea of l-values and r-values, deriving from the typical mode of evaluation on the left and right-hand side of an assignment statement. An l-value refers to an object that persists beyond a single expression. An r-value is a temporary value that does not persist beyond the expression that uses it.
The notion of l-values and r-values was introduced by
Combined Programming Language
Combined may refer to:
* Alpine combined (skiing), the combination of slalom and downhill skiing as a single event
** Super combined (skiing)
* Nordic combined (skiing), the combination of cross country skiing and ski jumping as a single event
* T ...
(CPL). The notions in an expression of r-value, l-value, and r-value/l-value are analogous to the
parameter
A parameter (), generally, is any characteristic that can help in defining or classifying a particular system (meaning an event, project, object, situation, etc.). That is, a parameter is an element of a system that is useful, or critical, when ...
modes of input parameter (has a value),
output parameter
In computer programming, a parameter or a formal argument is a special kind of variable used in a subroutine to refer to one of the pieces of data provided as input to the subroutine. These pieces of data are the values of the arguments (often c ...
(can be assigned), and input/output parameter (has a value and can be assigned), though the technical details differ between contexts and languages.
R-values and addresses
In many languages, notably the
C family, l-values have
storage addresses that are programmatically accessible to the running program (e.g., via some address-of operator like "&" in C/C++), meaning that they are variables or
de-referenced references to a certain memory location. R-values can be l-values (see below) or non-l-values—a term only used to distinguish from l-values. Consider the C expression . When executed, the computer generates an integer value of 13, but because the program has not explicitly designated where in the computer this 13 is stored, the expression is a non l-value. On the other hand, if a C program declares a variable x and assigns the value of 13 to x, then the expression has a value of 13 and is an l-value.
In C, the term l-value originally meant something that could be assigned to (hence the name, indicating it is on the left side of the assignment operator), but since the reserved word (constant) was added to the language, the term is now 'modifiable l-value'. In
C++11
C++11 is a version of the ISO/IEC 14882 standard for the C++ programming language. C++11 replaced the prior version of the C++ standard, called C++03, and was later replaced by C++14. The name follows the tradition of naming language versions by ...
a special semantic-glyph exists ( not to be confused with the
&&
operator used for logical operations ), to denote the ''use/access of the expression's address for the ''compiler'' only''; i.e., the address cannot be retrieved using the address-of operator during the ''run-time'' of the program (see
the use of move semantics). The addition of move semantics complicated the value classification taxonomy by adding to it the concept of an xvalue(expiring value) which refers to an object near the end of its lifetime whose resources can be reused (typically by moving them). This also lead to the creation of the categories glvalue(generalized lvalue) which are lvalues and xvalues and prvalues(pure rvalues) which are rvalues that are not xvalues.
This type of reference can be applied to ''all'' r-values including non-l-values as well as l-values. Some processors provide one or more instructions which take an immediate value, sometimes referred to as "immediate" for short. An immediate value is stored as part of the instruction which employs it, usually to load into, add to, or subtract from, a register. The other parts of the instruction are the
opcode
In computing, an opcode (abbreviated from operation code, also known as instruction machine code, instruction code, instruction syllable, instruction parcel or opstring) is the portion of a machine language instruction that specifies the operat ...
, and destination. The latter may be implicit. (A non-immediate value may reside in a register, or be stored elsewhere in memory, requiring the instruction to contain a direct or indirect address
.g., index register addressto the value.)
The l-value expression designates (refers to) an object. A non-modifiable l-value is addressable, but not assignable. A modifiable l-value allows the designated object to be changed as well as examined. An r-value is any expression, a non-l-value is any expression that is not an l-value. One example is an "immediate value" (look below) and consequently not addressable..
In assembly language
A value can be virtually any kind of data by a given
data type
In computer science and computer programming, a data type (or simply type) is a set of possible values and a set of allowed operations on it. A data type tells the compiler or interpreter how the programmer intends to use the data. Most progra ...
, for instance a string, a digit, a single letter.
Processors often support more than one size of immediate data, e.g. 8 or 16 bit, employing a unique opcode and mnemonic for each instruction variant. If a programmer supplies a data value that will not fit, the assembler issues an "Out of range" error message. Most assemblers allow an immediate value to be expressed as
ASCII
ASCII ( ), abbreviated from American Standard Code for Information Interchange, is a character encoding standard for electronic communication. ASCII codes represent text in computers, telecommunications equipment, and other devices. Because of ...
,
decimal
The decimal numeral system (also called the base-ten positional numeral system and denary or decanary) is the standard system for denoting integer and non-integer numbers. It is the extension to non-integer numbers of the Hindu–Arabic numeral ...
,
hexadecimal
In mathematics and computing, the hexadecimal (also base-16 or simply hex) numeral system is a positional numeral system that represents numbers using a radix (base) of 16. Unlike the decimal system representing numbers using 10 symbols, hexa ...
,
octal
The octal numeral system, or oct for short, is the radix, base-8 number system, and uses the Numerical digit, digits 0 to 7. This is to say that 10octal represents eight and 100octal represents sixty-four. However, English, like most languages, ...
, or
binary
Binary may refer to:
Science and technology Mathematics
* Binary number, a representation of numbers using only two digits (0 and 1)
* Binary function, a function that takes two arguments
* Binary operation, a mathematical operation that t ...
data. Thus, the ASCII character is the same as or . The
byte order
In computing, endianness, also known as byte sex, is the order or sequence of bytes of a word of digital data in computer memory. Endianness is primarily expressed as big-endian (BE) or little-endian (LE). A big-endian system stores the most sig ...
of strings may differ between processors, depending on the assembler and computer architecture.
Notes
References
*
* {{cite journal, first=Christopher, last=Strachey, author-link=Christopher Strachey, title=Fundamental Concepts in Programming Languages, journal=
Higher-Order and Symbolic Computation
''Higher-Order and Symbolic Computation'' (formerly ''LISP and Symbolic Computation''; print: , online: ) was a computer science journal published by Springer Science+Business Media. It focuses on programming concepts and abstractions and programm ...
, volume=13, pages=11–49, year=2000, doi=10.1023/A:1010000313106
External links
Value Object
Computer data
Programming language concepts
Type theory