🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Greg McGary Mon, 13 Nov 1995 18:08
reinterpret_cast<> and discarding const
#2552
Author: Greg McGary
Date: Mon, 13 Nov 1995 18:08
20 lines
1277 bytes
C++ Std sez (draft std and all recent WPs) in 5.2.9 (2) `The
reinterpret_cast operator shall not cast away constness.'

Unfortunately, whereas this might be possible to enforce for a single
reinterpret_cast<>, a sequence of two can easily discard
cv-qualifiers:

    char const *const *const *const ccpcpcpc;
    char *** cppp;
    cppp = reinterpret_cast<char ***> (reinterpret_cast<int> (ccpcpcpc))

Nasty.

Does a conforming compiler have any responsibility to detect this hole
(seems doable, but definitely a hassle), or is it just an unfortunate
wart?
---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads