Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Reference (computer science)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Language support== === Assembly === In [[assembly language]], 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. === Lisp === One of the earliest opaque references was that of the [[Lisp (programming language)|Lisp]] language [[cons|cons cell]], which is simply a [[object composition|record]] containing two references to other Lisp objects, including possibly other cons cells. This simple structure is most commonly used to build singly [[linked list]]s, but can also be used to build simple [[binary tree]]s and so-called "dotted lists", which terminate not with a null reference but a value. === C/C++ === {{Further|Reference (C++)}} The [[Pointer (computer programming)|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 typing|weak type system]] which can be violated using [[Cast (computer science)|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, a [[reference type]] <code>&</code>, and smart pointers in [[C++ standard library|its standard library]], but still retained the ability to circumvent these safety mechanisms for compatibility. ===Fortran=== Fortran does not have an explicit representation of references, but does use them implicitly in its [[call-by-reference]] calling semantics. A [[Fortran]] reference is best thought of as an ''alias'' of another object, such as a scalar variable or a row or column of an array. There is no syntax to dereference the reference or manipulate the contents of the referent directly. Fortran references can be null. As in other languages, these references facilitate the processing of dynamic structures, such as linked lists, queues, and trees. ===Object-oriented languages=== A number of object-oriented languages such as [[Eiffel (programming language)|Eiffel]], [[Java (programming language)|Java]], [[C Sharp (programming language)|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. References are extensively used to access and [[Assignment (computer science)#Assignment in object oriented languages|assign]] objects. References are also used in function/[[Method (computer programming)|method]] calls or message passing, and [[Reference counting|reference counts]] are frequently used to perform [[Garbage collection (computer science)|garbage collection]] of unused objects. ===Functional languages=== In [[Standard ML]], [[OCaml]], and many other functional languages, most values are persistent: they cannot be modified by assignment. Assignable "reference cells" provide [[mutable|mutable variables]], data that can be modified. Such reference cells can hold any value, and so are given the [[polymorphism (computer science)|polymorphic]] type <code>Ξ± ref</code>, where <code>Ξ±</code> is to be replaced with the type of value pointed to. These mutable references can be pointed to different objects over their lifetime. For example, this permits building of circular data structures. The reference cell is functionally equivalent to a mutable array of length 1. To preserve safety and efficient implementations, references cannot be [[Type conversion|type-cast]] in ML, nor can pointer arithmetic be performed. In the functional paradigm, many structures that would be represented using pointers in a language like C are represented using other facilities, such as the powerful [[algebraic datatype]] mechanism. The programmer is then able to enjoy certain properties (such as the guarantee of immutability) while programming, even though the compiler often uses machine pointers "under the hood". === Perl/PHP === [[Perl]] supports hard references, which function similarly to those in other languages, and '''symbolic references''', which are just string values that contain the names of variables. When a value that is not a hard reference is dereferenced, Perl considers it to be a symbolic reference and gives the variable with the name given by the value.<ref>{{cite web|url=http://perldoc.perl.org/perlref.html#Symbolic-references |title=perlref |publisher=perldoc.perl.org |access-date=2013-08-19}}</ref> [[PHP]] has a similar feature in the form of its <code>$$var</code> syntax.<ref>{{cite web|url=http://www.php.net/manual/en/language.variables.variable.php |title=Variable variables - Manual |publisher=PHP |access-date=2013-08-19}}</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)