Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #7835

Re: removing constness of a true const

From "Johannes Schaub (litb)" <schaub.johannes@googlemail.com>
Newsgroups comp.lang.c++
Subject Re: removing constness of a true const
Followup-To comp.lang.c++
Date 2011-07-15 15:02 +0200
Organization albasani.net
Message-ID <ivpdnr$okd$1@news.albasani.net> (permalink)
References <1e55c267-2789-498c-a5a1-f56e499336e5@z12g2000yqj.googlegroups.com>

Followups directed to: comp.lang.c++

Show all headers | View raw


siddhu wrote:

> I guess removing constness of a true const( I guess it is also called
> bitwise const ) using const_cast  is undefined behavior. Can you
> please give an example of a true const and may be a sample code which
> exhibits undefined behavior by removing constness of a true const.

Some folks here mentioned literals like double or int literals. But those 
are not const, and const cannot meaningfully applied to them. 

What "const" means is that the stored value of an object does not change 
from one to another value. Changing the object may change the stored value 
to something else. "const" prevents such changes to the object.

A value in and of itself does not convey a meaning of "const". Hence, in 
C++, non-class and non-array rvalues cannot be const qualified. That makes a 
great deal of sense, because they are not objects. 

It should be mentioned that the C++ Standard does not know a strict 
distinction between "value" and "object". In my text above, I used "value" 
in the sense of "the abstract meaning designated by an object's value 
representation", as defined by 3.9p4 (sadly that definition of "value" isn't 
used consistently throughout the spec or draft). 

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

removing constness of a true const siddhu <siddharth.sng@gmail.com> - 2011-07-14 08:07 -0700
  Re: removing constness of a true const Victor Bazarov <v.bazarov@comcast.invalid> - 2011-07-14 11:55 -0400
    Re: removing constness of a true const siddhu <siddharth.sng@gmail.com> - 2011-07-14 09:25 -0700
      Re: removing constness of a true const Victor Bazarov <v.bazarov@comcast.invalid> - 2011-07-14 16:18 -0400
        Re: removing constness of a true const "Balog Pal" <pasa@lib.hu> - 2011-07-15 01:18 +0200
          Re: removing constness of a true const Victor Bazarov <v.bazarov@comcast.invalid> - 2011-07-15 08:17 -0400
            Re: removing constness of a true const "Balog Pal" <pasa@lib.hu> - 2011-07-15 18:04 +0200
              Re: removing constness of a true const Ian Collins <ian-news@hotmail.com> - 2011-07-16 08:36 +1200
                Re: removing constness of a true const "Balog Pal" <pasa@lib.hu> - 2011-07-16 02:00 +0200
            Re: removing constness of a true const Paavo Helde <myfirstname@osa.pri.ee> - 2011-07-15 16:08 -0500
              Re: removing constness of a true const Ian Collins <ian-news@hotmail.com> - 2011-07-16 09:30 +1200
  Re: removing constness of a true const "Balog Pal" <pasa@lib.hu> - 2011-07-14 19:05 +0200
    Re: removing constness of a true const siddhu <siddharth.sng@gmail.com> - 2011-07-14 12:05 -0700
      Re: removing constness of a true const "Bo Persson" <bop@gmb.dk> - 2011-07-14 23:33 +0200
        Re: removing constness of a true const Victor Bazarov <v.bazarov@comcast.invalid> - 2011-07-14 17:46 -0400
          Re: removing constness of a true const "Bo Persson" <bop@gmb.dk> - 2011-07-16 08:32 +0200
  Re: removing constness of a true const "Johannes Schaub (litb)" <schaub.johannes@googlemail.com> - 2011-07-15 15:02 +0200
    Re: removing constness of a true const Victor Bazarov <v.bazarov@comcast.invalid> - 2011-07-15 09:54 -0400

csiph-web