Reference (computer Science) - Language Support

Language Support

In assembly languages, the first languages used, it is typical to express references using either raw memory addresses or indexes into tables. These work, but are somewhat tricky to use, because an address tells you nothing about the value it points to, not even how large it is or how to interpret it; such information is encoded in the program logic. The result is that misinterpretations can occur in incorrect programs, causing bewildering errors.

One of the earliest opaque references was that of the Lisp language cons cell, which is simply a record containing two references to other Lisp objects, including possibly other cons cells. This simple structure is most commonly used to build singly linked lists, but can also be used to build simple binary trees and so-called "dotted lists", which terminate not with a null reference but a value.

Another early language, Fortran, does not have an explicit representation of references, but does use them implicitly in its call-by-reference calling semantics.

The pointer is still one of the most popular types of references today. It is similar to the assembly representation of a raw address, except that it carries a static datatype which can be used at compile-time to ensure that the data it refers to is not misinterpreted. However, because C has a weak type system which can be violated using casts (explicit conversions between various pointer types and between pointer types and integers), misinterpretation is still possible, if more difficult. Its successor C++ tried to increase type safety of pointers with new cast operators and smart pointers in its standard library, but still retained the ability to circumvent these safety mechanisms for compatibility.

A number of popular mainstream languages today such as Eiffel, Java, C#, and Visual Basic have adopted a much more opaque type of reference, usually referred to as simply a reference. These references have types like C pointers indicating how to interpret the data they reference, but they are typesafe in that they cannot be interpreted as a raw address and unsafe conversions are not permitted.

Read more about this topic:  Reference (computer Science)

Famous quotes containing the words language and/or support:

    The style of an author should be the image of his mind, but the choice and command of language is the fruit of exercise.
    Edward Gibbon (1737–1794)

    Every winter the liquid and trembling surface of the pond, which was so sensitive to every breath, and reflected every light and shadow, becomes solid to the depth of a foot or a foot and a half, so that it will support the heaviest teams, and perchance the snow covers it to an equal depth, and it is not to be distinguished from any level field. Like the marmots in the surrounding hills, it closes its eyelids and becomes dormant for three months or more.
    Henry David Thoreau (1817–1862)