Topic: volatile_cast?
Author: Oleg Zabluda <zabluda@math.psu.edu>
Date: 1998/01/14 Raw View
How come we have const_cast but no volatile_cast?
Oleg.
--
Life is a sexually transmitted, 100% lethal disease.
---
[ 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 ]
Author: jpotter@falcon.lhup.edu (John Potter)
Date: 1998/01/14 Raw View
Pete Becker <petebecker@acm.org> wrote:
: Oleg Zabluda wrote:
: >
: > How come we have const_cast but no volatile_cast?
: >
: const_cast adds and removes CV qualifiers. That is, you can change
: constness and volatileness with it. I suppose it could have been split
: into two different casts, but I don't see any significant benefits from
: doing this.
OK, let me show my ignorance. Which of the following (which I think
are all valid) are invalid?
T* pt;
T const* pct;
T volatile* pvt;
T const volatile* pcvt;
pt = const_cast<T*>(pct);
pt = const_cast<T*>(pvt);
pt = const_cast<T*>(pcvt);
pct = static_cast<T const*>(pt);
pct = const_cast<T const*>(pvt);
pct = const_cast<T const*>(pcvt);
pvt = static_cast<T volatile*>(pt);
pvt = const_cast<T volatile*>(pct);
pvt = const_cast<T volatile*>(pcvt);
pcvt = static_cast<T const volatile*>(pt);
pcvt = static_cast<T const volatile*>(pct);
pcvt = static_cast<T const volatile*>(pcvt);
Could I have used static_cast anywhere else?
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: herbs@cntc.com (Herb Sutter)
Date: 1998/01/14 Raw View
Oleg Zabluda <zabluda@math.psu.edu> wrote:
>How come we have const_cast but no volatile_cast?
We do have it. It's spelled "const_cast". :-)
---
Herb Sutter (mailto:herbs@cntc.com)
Current Network Technologies Corp. 2695 North Sheridan Way, Suite 150
www.cntc.com www.peerdirect.com Mississauga Ontario Canada L5K 2N6
[ 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 ]
Author: Matt Austern <austern@isolde.mti.sgi.com>
Date: 1998/01/14 Raw View
Oleg Zabluda <zabluda@math.psu.edu> writes:
> How come we have const_cast but no volatile_cast?
>
> Oleg.
We do; it's just spelled "const_cast".
You use const_cast to remove cv-qualifications, that is, const,
volatile, and const volatile.
[ 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 ]
Author: Pete Becker <petebecker@acm.org>
Date: 1998/01/15 Raw View
Oleg Zabluda wrote:
>
> How come we have const_cast but no volatile_cast?
>
const_cast adds and removes CV qualifiers. That is, you can change
constness and volatileness with it. I suppose it could have been split
into two different casts, but I don't see any significant benefits from
doing this.
-- Pete
---
[ 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 ]
Author: Pete Forman <gsez020@compo.bedford.waii.com>
Date: 1998/01/15 Raw View
>>>>> "Oleg" == Oleg Zabluda <zabluda@math.psu.edu> writes:
Oleg> How come we have const_cast but no volatile_cast?
const_cast cast can cast away volatility as well. Perhaps naming it
cv_cast would have made things clearer.
--
Pete Forman
Western Geophysical
pete.forman@bedford.waii.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 ]
[ 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 ]
Author: Pete Becker <petebecker@acm.org>
Date: 1998/01/15 Raw View
John Potter wrote:
>
> Pete Becker <petebecker@acm.org> wrote:
>
> : const_cast adds and removes CV qualifiers. That is, you can change
> : constness and volatileness with it. I suppose it could have been split
> : into two different casts, but I don't see any significant benefits from
> : doing this.
>
> OK, let me show my ignorance. Which of the following (which I think
> are all valid) are invalid?
>
> T* pt;
> T const* pct;
> T volatile* pvt;
> T const volatile* pcvt;
>
> pt = const_cast<T*>(pct);
> pt = const_cast<T*>(pvt);
> pt = const_cast<T*>(pcvt);
> pct = static_cast<T const*>(pt);
> pct = const_cast<T const*>(pvt);
> pct = const_cast<T const*>(pcvt);
> pvt = static_cast<T volatile*>(pt);
> pvt = const_cast<T volatile*>(pct);
> pvt = const_cast<T volatile*>(pcvt);
> pcvt = static_cast<T const volatile*>(pt);
> pcvt = static_cast<T const volatile*>(pct);
> pcvt = static_cast<T const volatile*>(pcvt);
>
> Could I have used static_cast anywhere else?
I don't think so, but it's late. The real point, though, is that you
could have used const_cast for all of these. The cases where you must
use const_cast to remove constness is when the constness occurs below
the top level:
T * const * p1;
T ** p2;
p2 = const_cast<T**>(p1);
p2 = static_cast<T**>(p1); // illegal
-- Pete
---
[ 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 ]