passing ref to ptr again as ref to ptr....

P

peter koch

peter koch wrote:
(e-mail address removed) wrote:
[...]
I certainly hope not. That wouldn't be conform. (I presume, of
course, that the compiler will only do so if the objects are
PODs as well. Otherwise, the code won't be identical.)
I believe you are wrong.

I'm sure I'm not.  The issue has been discussed before.




[snip]
But you compare two different types. I do know that for two
objects of the same type, if their adress compares equal, the
adresses must refer to the same object.

This is true for objects of different types as well, as long as
they are complete objects (e.g. not base classes or members of a
class or union).  Except, of course, objects with different
complete types must be different objects.
Can you tell me where in the standard, that requirement is stated? I
only found [expr.eq] which in the first paragraph states that:

"Pointers to objects or functions of the same type (after pointer
conversions) can be compared for equality. Two pointers of the same
type compare equal if and only if they are both null, both point to
the same function, or both represent the same address"

The way I read this paragraph, I do not see any support for your
statement, but you might have another paragraph/interpretation?
[snip]

/Peter
 
J

James Kanze

peter koch wrote:
(e-mail address removed) wrote:
[...]
I certainly hope not. That wouldn't be conform. (I presume, of
course, that the compiler will only do so if the objects are
PODs as well. Otherwise, the code won't be identical.)
I believe you are wrong.
I'm sure I'm not. The issue has been discussed before.
[snip]
But you compare two different types. I do know that for two
objects of the same type, if their adress compares equal, the
adresses must refer to the same object.
This is true for objects of different types as well, as long as
they are complete objects (e.g. not base classes or members of a
class or union). Except, of course, objects with different
complete types must be different objects.
Can you tell me where in the standard, that requirement is
stated? I only found [expr.eq] which in the first paragraph
states that:
"Pointers to objects or functions of the same type (after
pointer conversions) can be compared for equality. Two
pointers of the same type compare equal if and only if they
are both null, both point to the same function, or both
represent the same address"
The way I read this paragraph, I do not see any support for
your statement, but you might have another
paragraph/interpretation?

And what does "after pointer conversions" mean?

In fact, the answer is that certain pointer conversions
(explicit or otherwise) do not change what object is being
pointed to (although the results likely lie about its type).
Thus, there is a long tradition of using "void (*)()" as a
"generic" pointer to function type: casting two pointers to
arbitrary functions to this type, then comparing them, should
tell you whether they point to the same function or not.
 
P

peter koch

peter koch wrote:
(e-mail address removed) wrote:
[...]
I certainly hope not. That wouldn't be conform. (I presume, of
course, that the compiler will only do so if the objects are
PODs as well. Otherwise, the code won't be identical.)
I believe you are wrong.
I'm sure I'm not.  The issue has been discussed before. [snip]
But you compare two different types. I do know that for two
objects of the same type, if their adress compares equal, the
adresses must refer to the same object.
This is true for objects of different types as well, as long as
they are complete objects (e.g. not base classes or members of a
class or union).  Except, of course, objects with different
complete types must be different objects.
Can you tell me where in the standard, that requirement is
stated? I only found [expr.eq] which in the first paragraph
states that:
"Pointers to objects or functions of the same type (after
pointer conversions) can be compared for equality. Two
pointers of the same type compare equal if and only if they
are both null, both point to the same function, or both
represent the same address"
The way I read this paragraph, I do not see any support for
your statement, but you might have another
paragraph/interpretation?

And what does "after pointer conversions" mean?

I see what you mean! I did not interpret that as widely as you: I took
pointer-conversions to mean e.g. removing constness of one of the
functions. Does the above also apply for objects?
As it is trivial to make two object-pointers compare equal when the
two objects are unrelated, I guess that can't be the case. IMHO if the
intension is as you say, the paragraphs above is quite badly
formulated.
In fact, the answer is that certain pointer conversions
(explicit or otherwise) do not change what object is being
pointed to (although the results likely lie about its type).
Thus, there is a long tradition of using "void (*)()" as a
"generic" pointer to function type: casting two pointers to
arbitrary functions to this type, then comparing them, should
tell you whether they point to the same function or not.

This is not a tradition, I've seen before.

/Peter
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top