# Thread: "Pointers" <-- crappy name

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

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

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

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

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

8. I would say other (managed) languages trying to build on the idea of smart pointers.

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

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

11. 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 )

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

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

14. ## nope

Originally Posted by matsp
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. Originally Posted by quzah
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.