Value type
Encyclopedia
In computer science
Computer science
Computer science or computing science is the study of the theoretical foundations of information and computation and of practical techniques for their implementation and application in computer systems...

, the term value type is commonly used to refer to one of two kinds of data types: Types of values or Types of objects with deep copy semantics.

Types of Values

Elements of Programming defines a value to be a sequence of bits, called datum, together with its interpretation.
A value type, then, is a correspondence between a set of data and a set of abstract or concrete entities sharing characteristic attributes. The set of entities is sometimes called a species. For example, a value type—call it small_int_value— can establish the correspondence between a sequence of 16 bits and integers values from -32,768 to +32,767 through a two's complement representation.

Value types do not include constraints on how their values are stored. E.g., the type small_int_value in the example above does not determine byte order
Endianness
In computing, the term endian or endianness refers to the ordering of individually addressable sub-components within the representation of a larger data item as stored in external memory . Each sub-component in the representation has a unique degree of significance, like the place value of digits...

, alignment
Data structure alignment
Data structure alignment is the way data is arranged and accessed in computer memory. It consists of two separate but related issues: data alignment and data structure padding. When a modern computer reads from or writes to a memory address, it will do this in word sized chunks...

, or even the number of 8-bit byte
Byte
The byte is a unit of digital information in computing and telecommunications that most commonly consists of eight bits. Historically, a byte was the number of bits used to encode a single character of text in a computer and for this reason it is the basic addressable element in many computer...

s used to store the 16 bits of the value type's representation. Since the values underpinning value types are not stored, value types also do not include a notion of mutation. A type that does determine constraints for storage in random-access memory
Random-access memory
Random access memory is a form of computer data storage. Today, it takes the form of integrated circuits that allow stored data to be accessed in any order with a worst case performance of constant time. Strictly speaking, modern types of DRAM are therefore not random access, as data is read in...

 is often called an object type.

Programming Language Support

Pure functional programming
Functional programming
In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data. It emphasizes the application of functions, in contrast to the imperative programming style, which emphasizes changes in state...

 languages do not model state and their types are therefore value types in the sense described here.

In contrast, imperative programming
Imperative programming
In computer science, imperative programming is a programming paradigm that describes computation in terms of statements that change a program state...

 languages require a notion of object type. Imperative programming
Imperative programming
In computer science, imperative programming is a programming paradigm that describes computation in terms of statements that change a program state...

 languages also deal with values, but their type systems often do not distinguish the types of values from the types of objects. Instead, the context of an expressions
Expression (programming)
An expression in a programming language is a combination of explicit values, constants, variables, operators, and functions that are interpreted according to the particular rules of precedence and of association for a particular programming language, which computes and then produces another value...

 determines whether the storage characteristics associated with an object type plays a role or not. For example, in C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

 and C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...

, expressions are treated as lvalues or rvalues
Value (computer science)
In computer science, a value is an expression which cannot be evaluated any further . The members of a type are the values of that type. For example, the expression "1 + 2" is not a value as it can be reduced to the expression "3"...

—the latter can be thought of as having value types.

Types of Objects with Deep Copy Semantics

Some programming languages—notably C#—use the term value type to refer to the types of objects for which assignment has deep copy semantics (as opposed to reference types
Reference type
In programming language theory, a reference type is a data type that can only be accessed by references. Unlike objects of value types, objects of reference types cannot be directly embedded into composite objects and are always dynamically allocated...

, which have shallow copy semantics). For example:

int i1 = 42; // "int" is a value type.
int i2 = i1; // i2 uses distinct storage for its value:
// the value of i1 is "deep-copied" into i2.

object o1 = i1; // "Boxing" (see below) from the value type "int"
// to a reference type compatible with "object".
object o2 = o1; // Since o1 and o2 have reference type, they
// now refer to the same value storage; i.e.,
// o1 is "shallow-copied" into o2.


Other programming languages—e.g., Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

—do not formally define the term value type, but their practitioners informally use the term to refer to types with deep copy semantics (such as Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

's primitive type
Primitive type
In computer science, primitive data type is either of the following:* a basic type is a data type provided by a programming language as a basic building block...

s).

Boxing and Unboxing

Programming languages that distinguish between value types and reference types
Reference type
In programming language theory, a reference type is a data type that can only be accessed by references. Unlike objects of value types, objects of reference types cannot be directly embedded into composite objects and are always dynamically allocated...

 typically offer a mechanism, called boxing, to wrap some or all of their value types in reference types
Reference type
In programming language theory, a reference type is a data type that can only be accessed by references. Unlike objects of value types, objects of reference types cannot be directly embedded into composite objects and are always dynamically allocated...

. This permits the use of value types in contexts expecting reference types
Reference type
In programming language theory, a reference type is a data type that can only be accessed by references. Unlike objects of value types, objects of reference types cannot be directly embedded into composite objects and are always dynamically allocated...

. The converse process (to unwrap the value type) is known as unboxing.
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK