Thread: "Pointers" <-- crappy name

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    29

    "Pointers" <-- crappy name

    I just had a thought today I wanted to share. There are a million and 1 "tutorials" out there that try to explain pointers.. like they are difficult to understand. The only thing difficult to understand about them, is why they are called "pointers" when they are more like "maps".

    Heres my pointer tutorial:

    Every location in memory has a hexidecimal address. when you want to share your variable with another function, you send it that hexidecimal address, so it knows where to put the value. If you want to see the address, you use the '&' sign. If you want to see the value, you use the '*' sign.

    And thats what a "pointer" is.. er.. basically.

    just a thought.

  2. #2
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    > is why they are called "pointers" when they are more like "maps".
    Not really, a map has a different meaning.

    Plus "maps" don't support arithmetic.

    > Every location in memory has a hexidecimal address
    Sure, Hexadecimal, Octal, Binary, Decimal, or however you wish to interpret it. More often than not they're stored in binary .

    You explained references in a way, more than you did pointers. :-)

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Well, it's not only C that calls a pointer a pointer. Pascal (and Modula-2/3) as well as their ancestors Algol and related Simula. Intel assembler also uses the form "byte ptr [eax]"

    So whilst it may seem illogical to you, it is common in a lot of computer programming at several levels.

    Techncially, addresses aren't hex numbers. Hex is just a simpler way of describing the value of an address in a way that can be trasnslated to binary. An address is simply a number - internally stored as binary, but so is all integers, and you wouldn't say "integers are actually hexadecimal values", would you?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    29

    nope

    Quote Originally Posted by matsp View Post
    Well, it's not only C that calls a pointer a pointer. Pascal (and Modula-2/3) as well as their ancestors Algol and related Simula. Intel assembler also uses the form "byte ptr [eax]"

    So whilst it may seem illogical to you, it is common in a lot of computer programming at several levels.

    Techncially, addresses aren't hex numbers. Hex is just a simpler way of describing the value of an address in a way that can be trasnslated to binary. An address is simply a number - internally stored as binary, but so is all integers, and you wouldn't say "integers are actually hexadecimal values", would you?

    --
    Mats
    You could, but it wouldn't make sense. Mostly I just think alot of confusion from beginning people (like myself) is the term "pointers" because.. really.. does it "point" to anything, or is just an address send to a function to tell that function where to store it's value?

    As everyone here knows, to a computer any value of any sort is simply a combination of "on" or "off", 1 or 0, whatever. octal, hex, and the like are used (from what I understand) because values get so big, that doing everything in binary would be much less efficient, and as technology grows, so does capacitance. Therefore it is ALL binary, just in different form.

  5. #5
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by argv View Post
    Mostly I just think alot of confusion from beginning people (like myself) is the term "pointers" because.. really.. does it "point" to anything, or is just an address send to a function to tell that function where to store it's value?
    The last phrase is correct, but the "or is" is sort of non-sensical, like "is the sky really blue, or is it just the color of oxygen in the atmosphere?". The sky is blue, the color of oxygen in the atmosphere. A pointer is an address sent to a function that points to where a value is stored.

    Going back to the street metaphor, and the Original Post, a map would be something of an area. If I wrote "123 Elm St." down on a piece of paper and gave it to you, you would not call it a map. And in fact map is a term in programming you will discover later, and it involves regions of memory.

    Some (non-compiled) languages use something called a reference which is functionally identical to a pointer. The only word I have heard that might be more descriptive than "pointer" is "reference". On the other hand, pointer is a more unique word than "reference" -- it is not so overloaded semantically. So once you get the concept, pointer is probably more convenient, immediately recognizable, and less likely to be confused with something else. Maybe "referer" would be good if you do not have to say it five times fast

    That makes sense to me, but so many books and 'tutorials' and whatever do a horrible job of explaining what a pointer is.
    I agree 100% on that. But it is not because of the name; it is because of the strong elliptical tradition in programming "instructional" discourse, which is virtually the de facto standard. You could call it anything, it will not improve the quality of the material to which you refer.

    Quote Originally Posted by brewbuck View Post
    The question is not what a pointer IS (most people can understand that part) but why you would need one.
    Bravo brewbuck. That's the rub.
    Last edited by MK27; 05-25-2009 at 09:51 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  6. #6
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by MK27 View Post
    Some (non-compiled) languages use something called a reference which is functionally identical to a pointer. The only word I have heard that might be more descriptive than "pointer" is "reference". On the other hand, pointer is a more unique word than "reference" -- it is not so overloaded semantically. So once you get the concept, pointer is probably more convenient, immediately recognizable, and less likely to be confused with something else.
    Reference is the concept, pointer is the implementation. The fact that a pointer is an address enables a lot of syntax you wouldn't have otherwise -- subtraction of pointers, incrementing and decrementing, testing for NULL, etc.

    References I think are more confusing, because often they automagically dereference themselves, which is hard to explain. And they need not be implemented in terms of addresses, so it's difficult to talk about what a reference is actually "made of" other than saying it's just some sort of magic object that stands for some other object.

    People have trouble with abstraction. Some people can't even grasp why functions are important. I'm not surprised that a lot of people can't figure out pointers, but what bothers me is the claim that pointers are intrinsically difficult to understand.

    They aren't. What's hard to understand is why on Earth you'd need one.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  7. #7
    Registered User
    Join Date
    May 2009
    Posts
    29

    well....

    Quote Originally Posted by brewbuck View Post
    Reference is the concept, pointer is the implementation. The fact that a pointer is an address enables a lot of syntax you wouldn't have otherwise -- subtraction of pointers, incrementing and decrementing, testing for NULL, etc.

    References I think are more confusing, because often they automagically dereference themselves, which is hard to explain. And they need not be implemented in terms of addresses, so it's difficult to talk about what a reference is actually "made of" other than saying it's just some sort of magic object that stands for some other object.

    People have trouble with abstraction. Some people can't even grasp why functions are important. I'm not surprised that a lot of people can't figure out pointers, but what bothers me is the claim that pointers are intrinsically difficult to understand.

    They aren't. What's hard to understand is why on Earth you'd need one.
    There are alot of things that are used just to make code more organized and readable. Like using #define for anything besides a macro. I like the idea of pointers, because I like the idea that I can create something in one spot, and then if I want another function to be able to change that value based on some sort of (whatever), then it can. Thats the magic I guess.

    It's not a huge deal to me, I'm not going to stand on the sidewalk preaching about how much I don't care for the term "pointer", I'm really just fueling conversation and debate I suppose. If I had to name it something, I would just call it an address. albeit, an address you can do math with, have a null value for, and whatever since it's not a text string, but an actual value.

  8. #8
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by brewbuck View Post
    References I think are more confusing, because often they automagically dereference themselves, which is hard to explain. And they need not be implemented in terms of addresses, so it's difficult to talk about what a reference is actually "made of" other than saying it's just some sort of magic object that stands for some other object.
    As someone who learned perl and C nearly concurrently, I would say the two slightly different concepts shed a lot of light on each other -- probably because the reference is not implemented as an address. The concept of "reference" is pure pragmatism. I remember feeling that very clearly. Of course, I am now ashamed to admit it took me longer than 5 minutes to completely grasp either

    Programming is magic, IMO. You could say a function "is a magical thing", a memory address "is a magical thing", etc, etc. Even with a knowledge of transistors and logic gates, I doubt anyone really conceptualizes all the way down to "reality" very often when writing code.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  9. #9
    Registered User
    Join Date
    May 2009
    Posts
    29

    true

    Quote Originally Posted by MK27 View Post
    The last phrase is correct, but the "or is" is sort of non-sensical, like "is the sky really blue, or is it just the color of oxygen in the atmosphere?". The sky is blue, the color of oxygen in the atmosphere. A pointer is an address sent to a function that points to where a value is stored.

    Going back to the street metaphor, and the Original Post, a map would be something of an area. If I wrote "123 Elm St." down on a piece of paper and gave it to you, you would not call it a map. And in fact map is a term in programming you will discover later, and it involves regions of memory.

    Some (non-compiled) languages use something called a reference which is functionally identical to a pointer. The only word I have heard that might be more descriptive than "pointer" is "reference". On the other hand, pointer is a more unique word than "reference" -- it is not so overloaded semantically. So once you get the concept, pointer is probably more convenient, immediately recognizable, and less likely to be confused with something else. Maybe "referer" would be good if you do not have to say it five times fast


    I agree 100% on that. But it is not because of the name; it is because of the strong elliptical tradition in programming "instructional" discourse, which is virtually the de facto standard. You could call it anything, it will not improve the quality of the material to which you refer.


    Bravo brewbuck. That's the rub.
    well, thats all I'm sayin really. (about the bad explainations)

  10. #10
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by argv
    Heres my pointer tutorial:

    Every location in memory has a hexidecimal address. when you want to share your variable with another function, you send it that hexidecimal address, so it knows where to put the value. If you want to see the address, you use the '&' sign. If you want to see the value, you use the '*' sign.
    Reasonably concise explanation, except that:
    • Hexadecimal is just a common representation for addresses so you should leave it out or comment as such.
    • You assume that the reader knows the context with which you talk about the address of and indirection operators.
    • You say nothing about pointer arithmetic and one past the end pointers.
    • You say nothing about null pointers and null pointer constants.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  11. #11
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Hmmm. I often have problems with "doctrine" but I would say pointer is a picture perfect word.

    A pointer is a value stored in memory. The value of the pointer is a (presumably different) address. If we met on the sidewalk, and you said "Where is the Masonic Lodge?", I would say "over there" and point to it.

    As for drawing a map, hopefully that will not be necessary
    Last edited by MK27; 05-24-2009 at 06:56 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  12. #12
    Registered User
    Join Date
    May 2009
    Posts
    29

    ...

    Quote Originally Posted by laserlight View Post
    Reasonably concise explanation, except that:
    • Hexadecimal is just a common representation for addresses so you should leave it out or comment as such.
    • You assume that the reader knows the context with which you talk about the address of and indirection operators.
    • You say nothing about pointer arithmetic and one past the end pointers.
    • You say nothing about null pointers and null pointer constants.
    No I did not. My main point really, is that most explainations of pointers really suck. The concept is not hard to get, I guess it's just who gives it to you. I'm very glad that I have a good teacher who does a really good job of explaining and driving home the concept.

    Still, I maintain that, from my understanding at least, it all boils down to the fact that a "pointer" is simply an address. Like if you wanna find someones house.. you use their address.. if you want to store a value created by another function, you use it's address. That just seems, to me, a better approach to the understanding of pointers.. but, maybe I'm wrong, since I learned how to do arithmetic with hexidecimal numbers before I learned what the heck a pointer was.. ??

  13. #13
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by argv View Post
    Still, I maintain that, from my understanding at least, it all boils down to the fact that a "pointer" is simply an address. Like if you wanna find someones house.. you use their address.. if you want to store a value created by another function, you use it's address. That just seems, to me, a better approach to the understanding of pointers.. but, maybe I'm wrong, since I learned how to do arithmetic with hexidecimal numbers before I learned what the heck a pointer was.. ??
    I still have no idea why you think hexadecimal has anything to do with pointers.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  14. #14
    Registered User
    Join Date
    May 2009
    Posts
    29

    ..

    Quote Originally Posted by brewbuck View Post
    I still have no idea why you think hexadecimal has anything to do with pointers.
    The hexidecimal thing really is just because thats what it is on *my* system, and thats what it shows up as when I'm in debug. It's ALL binary. I'm not saying that it's always a hexidecimal or octal, or binary anything. But it's an address, otherwise known as a combination of bits that represent a real value of some sort.

  15. #15
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by argv View Post
    Still, I maintain that, from my understanding at least, it all boils down to the fact that a "pointer" is simply an address. Like if you wanna find someones house.. you use their address.. if you want to store a value created by another function, you use it's address. That just seems, to me, a better approach to the understanding of pointers.. but, maybe I'm wrong, since I learned how to do arithmetic with hexidecimal numbers before I learned what the heck a pointer was.. ??
    There is a slight complication. A pointer contains an address (or, that is what it's value should be) but a pointer also has an address of it's own, where it's value is stored. The later is generally irrelevant, but this distinguishes the concept of "memory address" from "pointer".

    Pointer arithmetic generally does not involve hex. Eg, to move thru a string:
    Code:
    #include <stdio.h>
    
    int main() {
    	char string[]="hello world", *ptr=string;
    	int i;
    	while (ptr[0] != '\0') {
    		printf("%c",ptr[0]);
    		ptr++;
    	}
    	return 0;
    }
    Hex is just a form of notation. ++ is 1, which is 1 in dec and hex. If you wanted to skip to the end of string, you could use +=0xb, but most people would use +=11. Hex is used alot with mem address because the numbers are big and (possibly) because most programmers will recognize a hex number as a memory address (but that is not the only place it is used).
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Look at my crappy program. Look at it!
    By Hirumaru in forum C Programming
    Replies: 18
    Last Post: 03-12-2009, 01:17 AM
  2. <( ' '<) Simple Programming Question?
    By strigen in forum C Programming
    Replies: 1
    Last Post: 03-05-2009, 03:17 PM
  3. x = x < y < 2; WHY IS THIS ALWAYS TRUE!?
    By sh4k3 in forum C Programming
    Replies: 5
    Last Post: 06-08-2007, 01:00 AM
  4. > > > Urgent Help < < <
    By CodeCypher in forum C Programming
    Replies: 2
    Last Post: 01-31-2006, 02:06 PM