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/wildeye Jul 23 '08

They're right, you're confused on multiple issues. Another thing you're confused about is when you say "A pointer is not an address. A pointer has an address, and a pointer points to or contains an address, but a pointer is not itself an address."

That is simply wrong, from start to end. Not only is a pointer exactly the same thing as a machine address, as has already been said, but furthermore, pointers do not in general have addresses.

They are values. What you said is like saying "2 has an address". No, it does not. 2 is a value, and it can be stored in multiple addresses, it doesn't have to be (it might exist only in a machine register with no address), and certainly doesn't have to be contained in a unique address.

Perhaps you skipped the assembly language and machine architecture course. One pretty much cannot get confused about these particular issues if one has that prerequisite.

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.

6

u/[deleted] Jul 23 '08 edited Jul 24 '08

pointers do not in general have addresses.

Yeah. Pointers don't require storage! They're Magic!

A pointer has an address:

int main(void) {
    char *s = "foo";

    printf("%p\n", s);
    printf("%p\n", &s);

    return(0);
}

Prints:

0x8048480
0xbfc911c0

The first of which is the address in memory where the string "foo" resides. The second is the address in memory where the pointer resides.

edit: I understand we're just talking terminology here. The problem is, if you're not going to call it a 'pointer', then what are you gonna call it? In my interpretation, a pointer is the type. The pointer occupies memory (32 bits on a 32-bit architecture, AFAIK0, has an address, and contains an address. The pointer points to the address it contains, which is the address of something else in memory, whatever it is.

0

u/wildeye Jul 24 '08

It's not just terminology. Similarly to what I said nearby, "&a" is an address, but it doesn't have an address, now does it?

"&a" is a value, and although in some contexts it gets stuck in memory, it most certainly does not always get stuck in memory.

So since "&a" is a pointer, it follows that pointers do not always occupy memory.

You and others are thinking of the instances where there is a variable of type pointer-to-something. But pointers exist even in the absence of such variables, you see.