Chapter 32. Wild Pointers and Other Devilish Errors
FAQ 32.01 What is a wild pointer?
A wild pointer is a pointer that refers to garbage.
There are three ways to get a wild pointer.
- An uninitialized pointer that contains garbage bits
- A pointer that gets inadvertently scribbled on (for example, by another wild pointer; this is the domino effect)
- A pointer that refers to something that is no longer there (a dangling reference)
In C, the classic example of a dangling reference (3) occurs when a function returns a pointer to a local variable or when someone uses a pointer that has already been passed to
free. Both situations can occur in C++, too.
Wild pointers are bad news no matter how they are created. Bad enough that we devote this entire ...