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.

  1. An uninitialized pointer that contains garbage bits
  2. A pointer that gets inadvertently scribbled on (for example, by another wild pointer; this is the domino effect)
  3. 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 ...

Get C++ FAQs, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.