r/programming • • Jul 23 '08

Ask Programming: What language did you first start, and how old were you?

12 Upvotes

188 comments sorted by

View all comments

Show parent comment

6

u/munificent Jul 23 '08

Not only is a pointer exactly the same thing as a machine address

I'm not sure what your reference is, but it doesn't line up with mine. A pointer is a data type. An address is a value. Pointers hold addresses just like ints hold integers and char arrays hold strings.

Wikipedia says:

In computer science, a pointer is a programming language data type whose value refers directly to (or "points to") another value stored elsewhere in the computer memory using its address.

Pointers are a data type in C. You can declare variables of pointer types. Addresses are a property of RAM. Not the same.

What you said is like saying "2 has an address".

No, because 2 is not a pointer. Pointers are variables. What I said was:

int foo = 4;
int* pFoo = &foo;

pFoo contains an address (the address of foo, where 4 is stored in memory). It also has an address (&pFoo, which is wherever on the stack pFoo was created).

Perhaps you skipped the assembly language and machine architecture course.

No, I did not.

5

u/LoveGoblin Jul 23 '08

There are some very confused people in this thread, but you are not one of them.

To reinforce your point: read the example.

5

u/munificent Jul 23 '08

Thank you! I've been feeling like it's opposite day around here or something.

-1

u/wildeye Jul 24 '08

see above

0

u/LoveGoblin Jul 24 '08

Yeah, I did see above. Either you're just confused about terminology, or you fundamentally misunderstand pointers. Munificient is correct.

1

u/wildeye Jul 24 '08 edited Jul 24 '08

I've been doing compiler work longer, in all likelihood, than you've been alive, and you are getting tiresome with this "yes it is, no it isn't, yes it is, no it isn't" crap. Address my point about "&a" being a pointer, if you insist on continuing to be smug.

Edit: P.S. my comment about long time compiler work is not to claim superiority, it's to indicate why it irritates the hell out of me for you to continue to insist that I'm confused over newbie issues, without addressing the substance of my most recent comments (referred to with "see above", and which brought up "&a" as a pointer), and why I don't automatically take wikipedia to be authoritative -- I could write that article from scratch myself, and the phrasings would be more accurate if I did.

So put up or shut up.

P.P.S. it's also to indicate that I actually have expertise concerning the topic's application to many languages, not just C, and to its history, which I've studied -- but since one of my nearby comments that gave a URL for C.A.R. Hoare's thoughts was modded down, I guess this is a tough crowd -- neither interested in my anonymous expertise, nor that of a world famous computer scientist. :-P

Your loss.

1

u/LoveGoblin Jul 24 '08

Yeah yeah.

I'm not really doubting that you know what a pointer is, which is why I'm sure this is just a pedantic argument. As retarded as Internet Arguments get, the pedantic ones are the worst.

I think you're referring to "pointer" as the memory address itself, and munificent (and I) are using "pointer" to refer to the variable that contains that address. That's it.

Fuck I hate the Internet.

1

u/wildeye Jul 25 '08

Ok, that's all utterly reasonable. Sorry for contributing to hating the internet....I think we all started out meaning well, then got a bit irritated and short with each other. Thanks for closing this way.

-2

u/wildeye Jul 24 '08 edited Jul 24 '08

You said "a pointer has an address".

In C, "&foo" is a pointer. It also, without any possibility of argument, is a machine address: the location in RAM that the variable "foo" corresponds to."

But although "&foo" is an address, does it have an address? In general, no, unless you save it in a variable. More typically it is a value, and one which most often lives only in a register.

Everyone who modded you up and modded me down apparently misunderstand that central point.

I like wikipedia, and I contribute regularly, but on this topic, the particular phrasings used in wikipedia are seriously misleading.

The side issue of what is a type in C is not something that I intended to address here, but as a compiler professional, I certainly could talk about that side issue if you care.

But as a side note, if you check your textbooks you'll find that there is not an inherent dichotomy between "type" and "value". It depends on the language and usually also on which particular example constructs in a language are under discussion.

For instance, in C, "int a; &a;" the "&a" construct has type "pointer to int", and is a value. You can also of course say "typedef int **bp;", and then "bp" is (not has) type "pointer to int", and "bp" is not a value.

There are nuances to these things. But feel free to mod down people rather than discussing things. :-P

2

u/wildeye Jul 24 '08

Wonderful. Modded down again without contradicting my specific examples. That approach to critical thinking will get you guys far in life, I'm sure.