"Pointers" <-- crappy name

This is a discussion on "Pointers" <-- crappy name within the General Discussions forums, part of the Community Boards category; Originally Posted by argv what if I said "wheres minnesota?" Just kidding, but really, my point is (no pun intended) ...

  1. #16
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,272
    Quote Originally Posted by argv View Post
    what if I said "wheres minnesota?" Just kidding, but really, my point is (no pun intended) that for a beginner who knows nothing about the concept of passing information by value or by address, I would think a simple explaination that a "pointer" is nothing more than the address where a variable is stored. That makes sense to me, but so many books and 'tutorials' and whatever do a horrible job of explaining what a pointer is. They try to show you code, etc etc..
    I've tried using an explanation similar to yours. It doesn't help much. The question is not what a pointer IS (most people can understand that part) but why you would need one.

    And there's nothing special about hexadecimal. An address is an address, whether you express it in binary, decimal, hex, or encode it into a sonata using no instances of the musical note 'E'
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  2. #17
    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 10: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

  3. #18
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,272
    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);
    //}

  4. #19
    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.. ??

  5. #20
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,272
    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);
    //}

  6. #21
    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.

  7. #22
    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.

  8. #23
    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

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

    why you would need one

    Quote Originally Posted by brewbuck View Post
    I've tried using an explanation similar to yours. It doesn't help much. The question is not what a pointer IS (most people can understand that part) but why you would need one.

    And there's nothing special about hexadecimal. An address is an address, whether you express it in binary, decimal, hex, or encode it into a sonata using no instances of the musical note 'E'
    You could probably write many programs without using a single pointer. From what i've been told or read, pointers are more about increasing performance than about being something necessary. "Don't pass a copy of the whole structure, just pass the address" is, I suppose, the idea there.

    Of course, a programs gotta be pretty big before you have to worry about that much.

  10. #25
    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

  11. #26
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    I know that I have no idea how an instruction decoder works. So I can't get down to transistors. But I think the really useful knowledge ends at the micro architecture level.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  12. #27
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by argv View Post
    You could probably write many programs without using a single pointer.
    As long as they are just about ints. Remember:
    Code:
    char string[]="hello world";
    printf("%p",string);
    Technically, "string" is a pointer. However, there are slightly more restrictions on it vis. applying pointer arithmetic (not allowed!).
    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

  13. #28
    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)

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

    probably not..

    Quote Originally Posted by MK27 View Post
    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.
    No, probably not, but it might help. When determining how to write a program, I usually just as myself "how can I write it in a way that asks as few questions as possible." From the computers standpoint, well, it doesn't care. It'll do whatever, in order. The very concept of the computer or how computers came to be isn't magic. We needed a math machine because humans are not precise enough and prone to many mistakes. Back in the day, a human was called a "computer" if they computed stuff all day.

    I'm just thankful we got past the Babbage math machine. As much fun as that looked to be.

  15. #30
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Technically, "string" is a pointer.
    No, it isn't. string is an array. Which is not the same thing as a pointer.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Page 2 of 5 FirstFirst 12345 LastLast
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, 02: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, 02:00 AM
  4. > > > Urgent Help < < <
    By CodeCypher in forum C Programming
    Replies: 2
    Last Post: 01-31-2006, 02:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21