APLawrence - Information and Resources for Unix and Linux Systems, Bloggers and the self-employed
RSS Feeds Get APLawrence.com by RSS











(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Home > Misc. Words > 2005/02/12 pointer
Printer Friendly Version




pointer


Thou shalt not follow the NULL pointer, for chaos and madness await thee at its end. (Henry Spencer, found at http://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.


If this page was useful to you, please click to help others find it:  

Your +1's can help friends, contacts, and others on the web find the best stuff when they search.

1 comment




More Articles by Tony Lawrence - Find me on Google+



Click here to add your comments


"...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.

--BigDumbDinosaur





Sun Feb 13 08:58:48 2005:   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.


Don't miss responses! Subscribe to Comments by RSS or by Email

Click here to add your comments


If you want a picture to show with your comment, go get a Gravatar


cartoon
Versatile Site Map Generator $59.00
A1 Sitemap Generator

Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

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. We appreciate comments and article submissions.

Publishing your articles here

Jump to Comments



Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.

Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.

We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.


My Troubleshooting E-Book will show you how to solve tough problems on Linux and Unix systems!


book graphic unix and linux troubleshooting guide




 I sell and support
 Kerio Mail server
pavatar.jpg

This post tagged:

       - Basics
       - Programming




Unix/Linux Consultants

Skills Tests

Guest Post Here