Topic: What is an "address"? Was: ptrdiff_t is faulty?
Author: "Alan McKenney" <alan_mckenney1@yahoo.com>
Date: Fri, 1 Dec 2006 11:05:32 CST Raw View
Frederick Gotham wrote:
> This is forbidden by the C++ Standard. Every object must have a unique
> address.
What do you mean by "address" in this statement?
I wasn't aware that any language standard used the term "address."
Do you mean by that "pointer value"? (Which can only be compared
for identical types)
Or pointer bit pattern (what a binary dump would show)?
Or value after casting the pointer value to void *?
Or value after some sort of reinterpret_cast<> of the pointer value?
Or are you talking about something unrelated to pointer values?
Note that casts may change the bit pattern of pointer values,
and that the contents of a pointer may include more than a hardware
address, for some reasonable interpretation of the term "hardware
address", if there is any reasonable interpretation of the
term on the architecture you're interested in.
-- Alan McKenney
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: Keith Thompson <kst-u@mib.org>
Date: Sat, 2 Dec 2006 23:27:16 CST Raw View
"Alan McKenney" <alan_mckenney1@yahoo.com> writes:
> Frederick Gotham wrote:
>
>> This is forbidden by the C++ Standard. Every object must have a unique
>> address.
>
> What do you mean by "address" in this statement?
> I wasn't aware that any language standard used the term "address."
The C and C++ standards both use the term "address" extensively. For
example, unary "&" is the address-of operator. I don't see a formal
definition for the term in either standard, but it seems to be
synomymous with "pointer value".
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: fgothamNO@SPAM.com (Frederick Gotham)
Date: Sun, 3 Dec 2006 16:07:56 GMT Raw View
Alan McKenney:
>> This is forbidden by the C++ Standard. Every object must have a unique
>> address.
>
> What do you mean by "address" in this statement?
Pointer value.
> I wasn't aware that any language standard used the term "address."
"pointer value" will have to do then.
> Do you mean by that "pointer value"? (Which can only be compared
> for identical types)
A "pointer value" is an address. It's an identifier which indicates
where something is located. An address can take several forms:
0x2987D4F422
17 Greenlawns Avenue
The 2nd left past the garden centre.
554, byte position 3.
> Or pointer bit pattern (what a binary dump would show)?
Presumably, a pointer bit-pattern would be the result of memcpy'ing a
pointer.
int *p = 0;
char unsigned buf[sizeof p];
memcpy(buf,&p,sizeof p);
> Or value after casting the pointer value to void *?
If you cast (or implicitly convert) an object pointer to a void*, then
you have the address in the form of a byte address. This may be identical
to the object pointer, e.g. a value something like:
3536
, or it might be something more complex like:
3536, byte position 2
> Or value after some sort of reinterpret_cast<> of the pointer value?
If the casted-to pointer type describes an object type whose alignment
requirements are no stricter than the casted-from type, then you simply
have the address stored in a different pointer type. The addresses may be
represented identically, or they may be different insofar as the following
two addresses are different:
17 Greenlawns Avenue
and:
17 Ascaill na nGlasfhaichi
These addresses above are represented differently (in this case,
different spoken languages rather than different bit-patterns), but they're
still the same address. If we perform an equality test on these two
addresses, we'd expect it to be true:
(void*)(17 Greenlawns Avenue) == (void*)(17 Ascaill na nGlasfhaichi)
> Or are you talking about something unrelated to pointer values?
No.
> Note that casts may change the bit pattern of pointer values,
> and that the contents of a pointer may include more than a hardware
> address, for some reasonable interpretation of the term "hardware
> address", if there is any reasonable interpretation of the
> term on the architecture you're interested in.
If an implementation so desires, a pointer can hold a menagarie of
information, such as bounds-checking information.
--
Frederick Gotham
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]