tags:

views:

174

answers:

3

What are the official names for the operators * and & in the context of pointers? They seem to be frequently called dereference operator and address-of operator respectively, but unfortunately, the section on unary operators in the standard does not name them.

I really don't want to name & address-of anymore, because & returns a pointer, not an address. (see below) The standard is very clear about this:

The result of the unary & operator is a pointer to its operand.

Symmetry suggests to name & reference operator which is a little unfortunate because of the collision with references in C++. The fact that & returns a pointer suggests pointer operator. Are there any official sources that would confirm these (or other) namings?

pointers vs. addresses

A pointer is a language mechanism, while an address is an implementation detail. Addresses are untyped, while pointers aren't, except for void*. Kevlin Henney also distinguishes between pointers and addresses in an Interview:

C [...] allows us to abstract the specifics of the machine to the point that we are talking about pointers and not addresses. There is a whole load of pain that you no longer have to go through.

+2  A: 

The official names are address-of (&) (Found in 2.3.3. Pointers and Arrays) and dereference (or indirection operator) (*) (Found in 5.1.Pointers) operators.

according to "The C++ Programming Language", Third Edition by Bjarne Stroustrup.

Draco Ater
FredOverflow
Draco Ater
+11  A: 

From the C99 draft, at the index:

* (indirection operator), 6.5.2.1, 6.5.3.2

& (address operator), 6.3.2.1, 6.5.3.2

From the C++0x draft, at the index:

*, see indirection operator, see multiplication operator

&, see address-of operator, see bitwise AND operator

It's also referenced in 9.6/3 "The address-of operator & shall not be applied to a bit-field, so there are no pointers to bit-fields."

(So, sorry, you still need to call & "address-of" :p)

Personally I don't care the actual name as long as other can understand what I'm saying. I just call * "star" and & "and". :)

KennyTM
That's funny, I found the remark "see address-of operator" in the index, but there is no such entry in the current draft :) There is only one other mentioning of the "address-of operator" on page 219 regarding bit-fields. Am I blind, or can anyone confirm this?
FredOverflow
KennyTM
Ah, thank you very much, Kenny!
FredOverflow
A: 

Not true.

& does not return a pointer.

A pointer is a variable of pointer type, that may be used to contain address. Pointer has an address of it's own, usually different from its value, which is the address it holds.

As such, pointer is lvalue, and result of &p is not.

Example:

int *p, a, b;

p = &b; // valid, p is a pointer
&a = &b; // invalid, address is not a variable. lvalue required
Pavel Radzivilovsky
FredOverflow
In that case `a+b` doesn't return an `int` either because `a+b=*p // invalid, lvalue required`.
KennyTM
Alan
FredOverflow
@kenny: there is a term for rvalue expression evaluating to address. It is called "address". No need to call it pointer, and the standard doesn't.
Pavel Radzivilovsky