Topic: reinterpret_cast explanation required
Author: Steve Clamage <clamage@eng.sun.com>
Date: Tue, 12 Mar 2002 14:59:18 GMT Raw View
On Sat, 9 Mar 2002, Igor A. Goussarov wrote:
>
> As to 5.2.10p10, if 'x' is an lvalue of type T, then
> reinterpret_cast<U&>(x) yields an lvalue of type U, located at the same
> storage as x. That is, casting an lvalue to the reference to some other
> type effectively fakes the type of the object without altering its
> address.
> However, if I were to cast the pointer to x to the type "pointer to
> U" then according to 5.2.10p7 the result would be _unspecified_. But p10
> clarifies that reinterpret_cast<U&>(x) is equivalent to
> *reinterpret_cast<U*>(&x). Does it contradict with p7? Why does p7
> explicitly state that the result is unspecified while p10 specify this
> result perfectly?
>
Paragraph 3 says the mapping performed by reinterpret_cast is
implementation defined. Section 5.2.10 does not say you can fake
the type and get the same address.
Paragraph 10 defines the reference cast in terms of & and *.
Why do you think there is a contradiction in these areas?
--
Steve Clamage, stephen.clamage@sun.com
---
[ 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.research.att.com/~austern/csc/faq.html ]
Author: "Igor A. Goussarov" <igusarov@akella.com>
Date: Tue, 12 Mar 2002 17:45:51 GMT Raw View
Steve Clamage wrote:
>
> Paragraph 3 says the mapping performed by reinterpret_cast is
> implementation defined. Section 5.2.10 does not say you can fake
> the type and get the same address.
Then how do you interpret this cite from p10: "...the result is an
lvalue that refers to the same object as the source lvalue, but with a
different type". According to 1.8p1 "an object is a region of storage",
which makes me conclude that after the cast the result refers to the
same "region of storage". The latter is usually identified by its start
address. After all, the footnote 67 refers to such casts as "type pun".
What is it if not faking the type of the given object?
Igor
---
[ 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.research.att.com/~austern/csc/faq.html ]
Author: "Igor A. Goussarov" <igusarov@gate.studio1001.akella.ru>
Date: Sat, 9 Mar 2002 05:45:30 GMT Raw View
Hello group,
As to 5.2.10p10, if 'x' is an lvalue of type T, then
reinterpret_cast<U&>(x) yields an lvalue of type U, located at the same
storage as x. That is, casting an lvalue to the reference to some other
type effectively fakes the type of the object without altering its
address.
However, if I were to cast the pointer to x to the type "pointer to
U" then according to 5.2.10p7 the result would be _unspecified_. But p10
clarifies that reinterpret_cast<U&>(x) is equivalent to
*reinterpret_cast<U*>(&x). Does it contradict with p7? Why does p7
explicitly state that the result is unspecified while p10 specify this
result perfectly?
Igor
---
[ 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.research.att.com/~austern/csc/faq.html ]