Why do people call addresses "pointers"?

T

Thomas Stegen

Jack said:
No, a pointer is an object. It can contain an address.

And this address is sometimes called a pointer. Yes, even by
the standard.

Really though, pointers are types. The same goes for all types T,
you can have variables of type T and values of type T. Nothing
special about pointers there. The & operator for example returns
a value with type pointer to T.

And the standard is pretty clear that this:

int *func(void);

declares a function which returns _a pointer_. Clearly there is no
object being returned, just a value.
 
T

Thomas Stegen

Mike said:
The third (not just likely, but a fact).

The standard disagrees with you, hmm, strange. Something is
not factual here.

In the wider sense at least. Null pointer constants might not
be pointers, but there is at least something called null
pointers which are returned by functions. Cause the standard
says so.

Clearly if we have p, which is a variable of type T* and n
which is an int type then p + n is a pointer.

If you disagree with that then you disagree that the expressions
(n) is an int. Because if you want to make the distinctions between
pointer variables and the values they hold then one should make the
distinction between int variables and the values they hold. I see
no reason to treat them differently at least.
 
L

Lawrence Kirby

Hi,

I'm just wondering why people/books/experts say "the function returns a
pointer to.." or "we have to send scanf a pointer to.." instead of "the
function returns the address of.." or "we have to send scanf the
address of.."

Isn't the lvalue called a POINTER TO and the (r)value called the
ADDRESS OF?

The term "pointer" can refer to a number of things including

1. an object
2. an lvalue
3. a value
4. a type

Ideally you would say a "pointer object" or a "pointer value" but
even without that the context makes it clear which it is referring to.

The term "pointer value" is closely related to the term "address" but some
people do choose to make a distinction, with an address being specifically
a pointer value that relates to a valid object or function. Consider a
null pointer. This is a pointer value (it is a legitimate result of a
pointer vaued expression and can be stored in a pointer object), but it is
often not considered to be a valid address. It was a fairly easy
distinction in C90 where only addresses by this definition could be
generated by the & operator. But in C99 this is valid

int *p1 = NULL, *p2;
p2 = &*p1;

and sets p2 to null.
Why do people refer to the (r)values moving around in a program as
pointers? (Am I missing something, or just reading too much into a
non-issue?)

Because it is perfectly legitimate to talk about a pointer value, and that
isn't necessarily the same as an address.
[I've noticed that experts almost never say "address of", but often time
beginners do... there must be something to it]

C has pointers as a first class concept. The term address is used in the
standard, but tends to refer to the inherent "location" property of any
object or function (except register variables and bit-fields), rather than
the value of an expression or value held in an object of pointer type.
This is similar in effect to the distinction I made between pointer value
and address above.

Lawrence
 
K

Keith Thompson

Thomas Stegen said:
Really though, pointers are types. The same goes for all types T,
you can have variables of type T and values of type T. Nothing
special about pointers there. The & operator for example returns
a value with type pointer to T.

Pointer types are types.
Pointer objects are objects.
Pointer values are values.

A "pointer", without qualification, most commonly refers to a pointer
object, but it can refer to a pointer value (or even, I suppose, to a
pointer type). The meaning is usually clear from the context.
 
R

Richard Bos

Thomas Stegen said:
The standard disagrees with you, hmm, strange. Something is
not factual here.

C&V, please.
In the wider sense at least. Null pointer constants might not
be pointers, but there is at least something called null
pointers which are returned by functions. Cause the standard
says so.

Yes, but it's important to realise that null pointer _constants_ are not
null pointers (yet).

Richard
 
M

Mike Wahler

Thomas Stegen said:
The standard disagrees with you, hmm, strange. Something is
not factual here.

In the wider sense at least. Null pointer constants might not
be pointers, but there is at least something called null
pointers which are returned by functions. Cause the standard
says so.

'null pointer constant' and 'null pointer' are distinct
concepts.
Clearly if we have p, which is a variable of type T* and n
which is an int type then p + n is a pointer.

It's an expression which has a pointer type. It's not
an object. A pointer is an object.
If you disagree with that then you disagree that the expressions
(n) is an int.

It's not. Expressions are not objects.

Because if you want to make the distinctions between
pointer variables and the values they hold then one should make the
distinction between int variables and the values they hold.

I do.
I see
no reason to treat them differently at least.

There is a distinction between an object and an expression.

-Mike
 
T

Thomas Stegen

Mike said:
'null pointer constant' and 'null pointer' are distinct
concepts.

Which is what I allude to above when I say: "Null pointer constants
might not be pointers".

I am not sure I agree to the fact that null pointer constants
are not pointers though.
It's an expression which has a pointer type. It's not
an object.

That much no one disagrees with.
A pointer is an object.

True, but can it also be a value? Look at the description of
malloc for example: It returns a pointer.

"The malloc function returns either a null pointer or a pointer to the
allocated space."

So either the standard is wrong and malloc does not return a pointer,
or you are wrong and expressions can be pointers.

So if you are saying that only objects can be pointers I would like
to see chapter and verse please. Especially in the light of the fact
that object do not have types except when evaluated for their value.
(And then they _may_ be regarded as being of a particular type.)
IOW, talking about an object being and int or a pointer seems informal
in the first place.

Now, I have no problem seeing why some want to say that only objects
can be pointers. I only contend the claim that this is anything other
than an informal colloquioal distinction.

It's not. Expressions are not objects.

It's not an object, that much is clear. Only an idiot (or a newbie)
could think that it is. But still, the standard talks about functions
returning ints. So if you want to say that expression cannot evaluate
to int then I want to see chapter and verse.
I do.




There is a distinction between an object and an expression.

That's irrelevant here though. The disctinction was between
different types, not object versus expression. (For my very
last statement.)

And the overall discussion is not expression versus object either,
it is whether an expression can be something (in this case a pointer).
 
K

Keith Thompson

Thomas Stegen said:
Which is what I allude to above when I say: "Null pointer constants
might not be pointers".

I am not sure I agree to the fact that null pointer constants
are not pointers though.

Null pointer constants are not pointers; they're constants.

A pointer is an entity that exists during execution of a program.
A null pointer constant is a construct that exists in the program
source. It has no more existence during program execution than a
comment does (though it may result in the creation of an execution
time pointer value).

[...]
True, but can it also be a value? Look at the description of
malloc for example: It returns a pointer.

"The malloc function returns either a null pointer or a pointer to the
allocated space."
[...]

Now, I have no problem seeing why some want to say that only objects
can be pointers. I only contend the claim that this is anything other
than an informal colloquioal distinction.

Agreed, the standard uses the term "pointer" to refer either to a
pointer value or to a pointer object. But this is separate from the
issue of null pointer constants.
 
P

pete

TTroy wrote:
[I've noticed that experts almost never say "address of", but often
time beginners do... there must be something to it]

Besides address values,
pointers are also capable of have a value of NULL,
which is not an adddress.
 
R

Romeo Colacitti

TTroy said:
Hi,

I'm just wondering why people/books/experts say "the function returns a
pointer to.." or "we have to send scanf a pointer to.." instead of "the
function returns the address of.." or "we have to send scanf the
address of.."

Isn't the lvalue called a POINTER TO and the (r)value called the
ADDRESS OF?

Why do people refer to the (r)values moving around in a program as
pointers? (Am I missing something, or just reading too much into a
non-issue?)

[I've noticed that experts almost never say "address of", but often
time beginners do... there must be something to it]


consider the following (which leads to a simple answer):

int i, *ptr_i;

ptr_i = &i;

the & address of operator always returns a value, so &i is a value that
represents the address of i and is of TYPE=pointer-to-int.

the left side of an = statement is always an lvalue, so ptr_i an lvalue
designating an object of TYPE=pointer-to-int

So both addresses(values) and the pointer variables that hold
them(objects) have TYPES that are pointer-to-something. The addresses
are pointer values, the objects are pointer objects.

So when someone says __________ is a "pointer", it simply either a
pointer value or a pointer object, as determined by the context.

So it isn't incorrect to say "malloc returns a pointer," because we
know that functions only return values, so the 'pointer' the above
sentence refers to is actually a 'pointer value' (where pointer values
are addresses of the objects pointed to).

Also it isn't incorrect to say that "we have to assign the address to a
pointer," because we know that only lvalues/objects can be assigned to,
so 'pointer' in this case refers to a 'pointer object.'

So it's simple, "pointer" is a general term that can refer to either a
"pointer object" or a "pointer value" depending on context.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top