"Pointers" <-- crappy name

This is a discussion on "Pointers" <-- crappy name within the General Discussions forums, part of the Community Boards category; I just had a thought today I wanted to share. There are a million and 1 "tutorials" out there that ...

  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
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,304
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    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 07: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

  6. #6
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    OP's got it all figured out. Should have submitted to C++ 0x, now we have to live forever with the archaic "pointer" nomenclature.


    I think a less usefull name is RAII (Resource Aquisition is Initialization). Basically it goes like this

    1. Tell someone to use RAII
    2. Said someone asks what that stands for
    3. Word out the Acronym
    4. Person asks what that means
    5. Explain to them the meaning
    6. Be told, "That's a silly name for it".

    But then I see how Bjarne names his variables and functions and it all makes sense.
    Here to Deceive, Inveigle, Obfuscate Since 1945

  7. #7
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    I've never understood the issues that people have with pointers. Perhaps its because a lot of books out there do a terrible job of explaining them or try to explain them in a simple fashion which ends up not being simple at all.

    Pointers, IMO, are one of the most powerful and therefore one of the most dangerous and most abused features of C/C++. And while other languages are rushing to remove them C++ is just trying to make them a bit smarter. I prefer the latter.
    Last edited by VirtualAce; 05-24-2009 at 08:02 PM.

  8. #8
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    I would say other (managed) languages trying to build on the idea of smart pointers.
    Here to Deceive, Inveigle, Obfuscate Since 1945

  9. #9
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    I would say other (managed) languages trying to build on the idea of smart pointers.
    Many of them have completely removed them by making everything a pointer under the hood but never exposing them to the programmer. If they provided the programmer with a choice of whether to use a smart pointer or not use a pointer at all that would be much different.
    Last edited by VirtualAce; 05-24-2009 at 08:06 PM.

  10. #10
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    If there's a box on the shelf, and I say "Without moving, or saying anything, where's the box?" What do you do? Point to it. Pointer is the perfect name, because that's all it actually does. It simply points to where something is in memory.

    "Where's this variable located?" *points*


    Quzah.
    Hope is the first step on the road to disappointment.

  11. #11
    Hail to the king, baby. Akkernight's Avatar
    Join Date
    Oct 2008
    Location
    Faroe Islands
    Posts
    717
    Just think of int* as a completely different type than int, just like char is different than int a int* stores adress', just like int stores non decimals, or how they are calls...
    So int a = 5; is valid, just as much as char a = 'a' is valid, and as much as int* = 0x344546 is valid, then the difference between char*, int*, double*, ect. is that this '0x450688' (some random adress) has to be the adress to one of the types which people consider them as... Like, int* has to be such a value (0x4546757) and it has to hold the address of a integer, same with every other type, char*, double* ... Now you all know how to explain it to noobs like me , so start preaching! >: D ( NOTE: I FAIL at explaining :S )
    Currently research OpenGL

  12. #12
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,029
    int* = 0x344546 is invalid in C++, but valid in C.
    The concept of pointers is simple, but when you start adding things together, it starts to get confusing.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  13. #13
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    int* = 0x344546 is invalid in C++, but valid in C.
    Lack of identifier aside, that's not valid C. It's just accepted by most C compilers because legacy C code is horrible.
    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

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

  15. #15
    Registered User
    Join Date
    May 2009
    Posts
    29
    Quote Originally Posted by quzah View Post
    If there's a box on the shelf, and I say "Without moving, or saying anything, where's the box?" What do you do? Point to it. Pointer is the perfect name, because that's all it actually does. It simply points to where something is in memory.

    "Where's this variable located?" *points*


    Quzah.

    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 just wish that when I first started working with C, someone had just said "Ok, a pointer is simply a memory address." Ok, thats simple. So, I'm passing an address. Awesome. I love the concept of pointers, just not the explaination of them.

Page 1 of 5 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