Topic: Casting - in order of appearance
Author: Attila.Feher@lmf.ericsson.se (Attila Feher)
Date: Thu, 5 Sep 2002 14:16:03 +0000 (UTC) Raw View
Hi All,
I am puzzled about the interpretation of C style casts in C++. The
5.4/5 paragraph in the standard lists the valid C++ style casts and
combinations in a specific order, and says:
"If a conversion can be interpreted in more than one of the ways listed
above, the interpretation that appears first in the list is used, even
if a cast resulting from that interpretation is ill-formed."
Dang. So why is Scott Meyers' example interpreted as a
reinterpret_cast?
8<-----
int x;
static_cast<double&>(x) = 5; // rejected
[SNIP]
int x;
(double&)x = 5; // not rejected
---->8
According to what I read it does not matter if it is ill-formed, and
static_cast is _before_ reinterpret_cast in the list of 5.4/5...
What I am missing here (a lot) is the "rules of interpretation". Is it
possible that this is missing from the standard? Is is something
"implied" somewhere? Is it something we should know from the C standard
and just use it here? But then again: what about references? What
about user defined types with conversion constructors and implicit
conversion operators? The C standard does not discuss those.
So I am lost. Where can I find the "rules of interpretation"?
Attila
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]