Topic: What is virtual inheritance ?
Author: jpotter@falcon.lhup.edu (John E. Potter)
Date: 1996/12/19 Raw View
James Albert Kanze (james-albert.kanze@vx.cit.alcatel.fr) wrote:
: While I'm at it, I would like to ask if anyone could explain to me what
: paragraph 6 of section 5.2.9 is supposed to mean. This is the paragraph
: which speaks about the "inverse of any standard conversion sequence",
: but as far as I can see, all of the cases are either explicitly
: enumerated elsewhere in the section, or explicitly excluded by the
: restrictions which follow the paragraph. (Follow-ups to this question
: to comp.std.c++.)
Do not have my CD1 handy, but memory says that the standard conversion
of pointer to void* and its inverse are not mentioned. So:
int i;
*static_cast<float*>(static_cast<void*>(&i)) = 3.14;
// But the inner one is standard
*static_cast<float*>(&i) = 3.14;
// If it works for pointers, it works for references
static_cast<float&>(i) = 3.14;
// But should it? There is no void&
My compiler accepts all of these. Cast arithmetic
static_cast + static_cast == reinterpret_cast
Is there a reinterpret_cast that can not be done with two static_casts?
John
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Author: kanze@gabi-soft.fr (J. Kanze)
Date: 1996/12/23 Raw View
jpotter@falcon.lhup.edu (John E. Potter) writes:
> James Albert Kanze (james-albert.kanze@vx.cit.alcatel.fr) wrote:
> : While I'm at it, I would like to ask if anyone could explain to me what
> : paragraph 6 of section 5.2.9 is supposed to mean. This is the paragraph
> : which speaks about the "inverse of any standard conversion sequence",
> : but as far as I can see, all of the cases are either explicitly
> : enumerated elsewhere in the section, or explicitly excluded by the
> : restrictions which follow the paragraph. (Follow-ups to this question
> : to comp.std.c++.)
>
> Do not have my CD1 handy, but memory says that the standard conversion
> of pointer to void* and its inverse are not mentioned. So:
>
> int i;
> *static_cast<float*>(static_cast<void*>(&i)) = 3.14;
> // But the inner one is standard
> *static_cast<float*>(&i) = 3.14;
> // If it works for pointers, it works for references
> static_cast<float&>(i) = 3.14;
> // But should it? There is no void&
>
> My compiler accepts all of these.
IMHO, it shouldn't, but I would agree that the standard could be clearer.
The exact words are: "The inverse of any standard conversion sequence,
other than the lvalue-to-rvalue, array-to-pointer, function-to-pointer,
and boolean conversions, can be performed explicitly using static_cast
subject to the restriction that the explicit conversion does not cast
away constness, and the following additional rules for specific cases:
[...]" One of the specific cases begins: "An rvalue of type 'pointer to
cv1 B' [...]". I would argue (although it is far from evident that this
is even what was intended) that this specific case includes *all*
pointer casts. (My argumentation may just be wishful thinking.
Logically, in my mind, casts to and from void* are reinterpret_cast's,
not static_cast's.)
With regards to the draft standard, a different interpretation would
make your first example correct; there is no possible interpretation
which would allow static_cast in the other two cases. These are exactly
the cases for which reinterpret_cast was designed.
> Cast arithmetic
>
> static_cast + static_cast == reinterpret_cast
>
> Is there a reinterpret_cast that can not be done with two static_casts?
*IF* you accept casting to/from void* amongst the static_cast, and you
accept the corresponding casts with references, probably not. I don't
accept either. My position concerning the void* is very debatable; on
the other hand, I really don't think that there was ever the slightest
intent to allow void&.
--
James Kanze +33 (0)3 88 14 49 00 email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
Conseils en informatique industrielle --
-- Beratung in industrieller Datenverarbeitung
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]