APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

2005/02/12 pointer

© February 2005 Tony Lawrence

Thou shalt not follow the NULL pointer, for chaos and madness await thee at its end. (Henry Spencer, found at https://www.sysprog.net/quotlang.html)

Programmers have all sorts of pointers: indirect pointers, dangling pointers, stack pointers, function pointers, array pointers.. but really all of these are just addresses; addresses that "point" to other things.

Let's say we have a list of 8 telephone numbers. I tell you that my number is the 5th in that list. The "5" is the pointer, the address that lets you find my number. Now let's make another list. This list is just numbers: 7, 6, 5 and so on. I tell you to go look at the 8th item in that list, and you find that is "5". The "3" is a pointer that points to "5". Finally, I have a list of names, and my name is 8th on the list. Next to it is the number three. So "8" is a pointer to "3" which in turn points to "5" - and yes, this is really how a lot of data structures are built and stored. The "3" that points to "5" is an "indirect" pointer, and the "8" that points to "3" is a double indirect pointer.

Confused? Here it is:

1 fred  7
2 tom   6
3 paul  4
4 mary  8
5 linda 2
6 art   1
7 perry 5
8 tony  3  --->

                  1     7
                  2     6
        -----> 3     5  -----> 
                  4     8
                  5     1
                  6     2
                  7     3
                  8     4

                    978-786-2123  (perry's number)
                    979-555-1212  (tom's number)
                    980-555-1212  (fred's number)
                    981-555-1212  (mary's number)
      ----->     982-555-1212  (my number)
                    983-555-1212  (linda's number)
                    984-555-1212  (art's number)
                    985-555-1212  (paul's number)

Finally, let's look at the 2nd item on our list of names. That has the number "6" on it, and when we go to look at the middle list, the 6th item has the number 9 in it. But wait, we only have 8 phone numbers. A mistake has been made, and that would be called a "dangling" pointer - something that doesn't point to anything useful or real. And of course, programmers make those mistakes too.

Got something to add? Send me email.

(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> 2005/02/12 pointer

1 comment

Inexpensive and informative Apple related e-books:

Take Control of High Sierra

Take Control of iCloud

Take Control of IOS 11

Take Control of OS X Server

Take Control of Preview

More Articles by © Tony Lawrence

"...and that would be called a "dangling" pointer..."

Dangling pointers are also called "wild" pointers, which are dangerous in a program. Writing to the "address" pointed to by a wild pointer can make your program go...well...wild and possibly crash. In the days of MS-DOS, wild pointers often resulted in system fatality.


Sun Feb 13 08:58:48 2005: 10   pcunix

Protected mode operating systems do help: an errant program that tries to write into someone else's address space just gets killed off rather than messing up something else.

It has always amazed me that there was actually a version of Xenix for the 8086, which of course had no hardware support for protecting memory.


Printer Friendly Version

Have you tried Searching this site?

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us

Printer Friendly Version

There is no reason anyone would want a computer in their home. (Ken Olson, president, chairman and founder of DEC)

Linux posts

Troubleshooting posts

This post tagged:



Unix/Linux Consultants

Skills Tests

Unix/Linux Book Reviews

My Unix/Linux Troubleshooting Book

This site runs on Linode