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!
=== Kinds defined by value === ====Null pointer==== {{Main|Null pointer}} A '''null pointer''' has a value reserved for indicating that the pointer does not refer to a valid object. Null pointers are routinely used to represent conditions such as the end of a [[List (computing)|list]] of unknown length or the failure to perform some action; this use of null pointers can be compared to [[nullable type]]s and to the ''Nothing'' value in an [[option type]]. ====Dangling pointer==== {{Main|Dangling pointer}} A '''dangling pointer''' is a pointer that does not point to a valid object and consequently may make a program crash or behave oddly. In the [[Pascal (programming language)|Pascal]] or [[C (programming language)|C programming languages]], pointers that are not specifically initialized may point to unpredictable addresses in memory. The following example code shows a dangling pointer: <syntaxhighlight lang="C"> int func(void) { char *p1 = malloc(sizeof(char)); /* (undefined) value of some place on the heap */ char *p2; /* dangling (uninitialized) pointer */ *p1 = 'a'; /* This is OK, assuming malloc() has not returned NULL. */ *p2 = 'b'; /* This invokes undefined behavior */ } </syntaxhighlight> Here, <code>p2</code> may point to anywhere in memory, so performing the assignment <code>*p2 = 'b';</code> can corrupt an unknown area of memory or trigger a [[segmentation fault]]. ====Wild branch==== Where a pointer is used as the address of the entry point to a program or start of a [[subroutine|function which doesn't return anything]] and is also either uninitialized or corrupted, if a call or [[unconditional branch|jump]] is nevertheless made to this address, a "[[wild branch]]" is said to have occurred. In other words, a wild branch is a function pointer that is wild (dangling). The consequences are usually unpredictable and the error may present itself in several different ways depending upon whether or not the pointer is a "valid" address and whether or not there is (coincidentally) a valid instruction (opcode) at that address. The detection of a wild branch can present one of the most difficult and frustrating debugging exercises since much of the evidence may already have been destroyed beforehand or by execution of one or more inappropriate instructions at the branch location. If available, an [[instruction set simulator]] can usually not only detect a wild branch before it takes effect, but also provide a complete or partial trace of its history.
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)