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
Pointer (computer programming)
(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!
==Making pointers safer== As a pointer allows a program to attempt to access an object that may not be defined, pointers can be the origin of a variety of [[software bug|programming errors]]. However, the usefulness of pointers is so great that it can be difficult to perform programming tasks without them. Consequently, many languages have created constructs designed to provide some of the useful features of pointers without some of their [[Anti-pattern|pitfalls]], also sometimes referred to as ''pointer hazards''. In this context, pointers that directly address memory (as used in this article) are referred to as '''{{visible anchor|raw pointer}}s''', by contrast with [[smart pointer]]s or other variants. One major problem with pointers is that as long as they can be directly manipulated as a number, they can be made to point to unused addresses or to data which is being used for other purposes. Many languages, including most functional programming languages and recent [[imperative programming]] languages like [[Java (programming language)|Java]], replace pointers with a more opaque type of reference, typically referred to as simply a ''reference'', which can only be used to refer to objects and not manipulated as numbers, preventing this type of error. Array indexing is handled as a special case. A pointer which does not have any address assigned to it is called a [[wild pointer]]. Any attempt to use such uninitialized pointers can cause unexpected behavior, either because the initial value is not a valid address, or because using it may damage other parts of the program. The result is often a [[segmentation fault]], [[storage violation]] or [[wild branch]] (if used as a function pointer or branch address). In systems with explicit memory allocation, it is possible to create a [[dangling pointer]] by deallocating the memory region it points into. This type of pointer is dangerous and subtle because a deallocated memory region may contain the same data as it did before it was deallocated but may be then reallocated and overwritten by unrelated code, unknown to the earlier code. Languages with [[garbage collection (computer science)|garbage collection]] prevent this type of error because deallocation is performed automatically when there are no more references in scope. Some languages, like [[C++]], support [[smart pointer]]s, which use a simple form of [[reference counting]] to help track allocation of dynamic memory in addition to acting as a reference. In the absence of reference cycles, where an object refers to itself indirectly through a sequence of smart pointers, these eliminate the possibility of dangling pointers and memory leaks. [[Delphi (programming language)|Delphi]] strings support reference counting natively. The [[Rust programming language]] introduces a ''borrow checker'', ''pointer lifetimes'', and an optimisation based around [[option type]]s for [[null pointer]]s to eliminate pointer bugs, without resorting to [[Garbage collection (computer science)|garbage collection]].
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)