Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #7844
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail |
|---|---|
| From | Ian Collins <ian-news@hotmail.com> |
| Newsgroups | comp.lang.c++ |
| Subject | Re: removing constness of a true const |
| Date | Sat, 16 Jul 2011 09:30:16 +1200 |
| Lines | 32 |
| Message-ID | <98bpt6Fv3qU2@mid.individual.net> (permalink) |
| References | <1e55c267-2789-498c-a5a1-f56e499336e5@z12g2000yqj.googlegroups.com> <ivn3hs$tk2$1@dont-email.me> <ce8312c9-10ef-46d5-a2bc-0c267526dbd3@a11g2000yqm.googlegroups.com> <ivnivf$a1l$1@dont-email.me> <ivntgo$4eq$1@news.ett.com.ua> <ivpb50$grt$1@dont-email.me> <Xns9F241661E29Cmyfirstnameosapriee@216.196.109.131> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | individual.net Oc6lucLl80D0d3hxrY4e9g8pk/8rqpO8HjqEGsmpLbXIZ9sB9J |
| Cancel-Lock | sha1:GQAJfUGT45ljl4IVyQsl4l/5yyU= |
| User-Agent | Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:1.9.2.9) Gecko/20101021 Lightning/1.0b2 Thunderbird/3.1.4 |
| In-Reply-To | <Xns9F241661E29Cmyfirstnameosapriee@216.196.109.131> |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.c++:7844 |
Show key headers only | View raw
On 07/16/11 09:08 AM, Paavo Helde wrote:
> Victor Bazarov<v.bazarov@comcast.invalid> wrote:
>>
>> Any data initializing which requires code to be executed at runtime
>> cannot be put in "the 'const' segment" - the segment would not be const,
>> would it?
>
> In principle the program can perform the dynamic initialisation of const
> objects at startup, then mark the relevant VM pages as read-only. I guess
> no implementation bothers to do such things currently.
>
> The most imminent danger with changing const objects is that the compiler
> is allowed to optimize away repeated reads of the data even if it cannot
> prove the data is not modified meanwhile. This might lead to subtle bugs,
> appearing probably only in optimized compilations. So even if the class
> object is not "truly const", it might effectively act as such.
A really simple example is:
void g( int );
int main()
{
const int n = 42;
int* p = const_cast<int*>(&n);
*p = 43;
g(n);
g(*p);
}
--
Ian Collins
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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