The basic idea behind references and pointers is pretty simple. Instead of having a variable holding an object, we want the variable to hold a reference to an object. Using this reference, we want to be able to access or change the object's contents.

Let's illustrate this with a simple example. The & operator obtains a reference to a variable's contents. The * operator accesses the contents referred to by a reference:

imm a = 3
imm ref = &a    // ref holds a reference to a's contents
imm val = *ref  // val is now 3

References (and pointers) offer several benefits:

Safety Challenges with References

Although references can be efficient and versatile, they can also be dangerous. Unless appropriate precautions are taken, use of raw pointers can cause serious logic failures:

Such failures are not always easy to detect and eliminate. The consequences for such logic failures might be minor, but they could be catastrophic, especially when malicious actors take advantage of undetected pointer problems to gain access or control over other peoples' privileges or information.

References vs. Pointers

One of Cone's key goals is to make it easier to build safe programs. To support this goal, Cone explicitly distinguishes between references and pointers as separate types:

Allocator vs. Borrowed References

References come in two flavors, distinguished by how they are created:

Related Information

Subsequent chapters provide detailed information about each of these distinct types: