From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9656 invoked by alias); 30 Jan 2011 21:01:40 -0000 Received: (qmail 9644 invoked by uid 22791); 30 Jan 2011 21:01:39 -0000 X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from mail-iw0-f175.google.com (HELO mail-iw0-f175.google.com) (209.85.214.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 30 Jan 2011 21:01:35 +0000 Received: by iwn8 with SMTP id 8so5088232iwn.20 for ; Sun, 30 Jan 2011 13:01:34 -0800 (PST) MIME-Version: 1.0 Received: by 10.42.170.138 with SMTP id f10mr6884362icz.269.1296421294122; Sun, 30 Jan 2011 13:01:34 -0800 (PST) Received: by 10.42.230.66 with HTTP; Sun, 30 Jan 2011 13:01:34 -0800 (PST) In-Reply-To: <20110130204022.GF29226@nibiru.local> References: <1296416236.32435.15.camel@sara> <878vy2dto4.fsf@Pulska.kon.iki.fi> <20110130204022.GF29226@nibiru.local> Date: Sun, 30 Jan 2011 21:02:00 -0000 Message-ID: Subject: Re: Optimizing From: Jonathan Wakely To: weigelt@metux.de, gcc-help@gcc.gnu.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2011-01/txt/msg00472.txt.bz2 On 30 January 2011 20:40, Enrico Weigelt wrote: > * Kalle Olavi Niemitalo wrote: > >> Although the second parameter is const void *, the language still >> allows the function to modify the object to which that points, >> provided that the object was not defined as const. > > Doesn't that defeat the whole purpose of const ? No. http://www.gotw.ca/gotw/081.htm > BTW: let me add another question: > > > =A0 =A0const std::string str; > > =A0 =A0void one(const std::string s) > =A0 =A0{ > =A0 =A0 =A0 =A0str =3D s; > =A0 =A0} > > =A0 =A0void two(const char* s) > =A0 =A0{ > =A0 =A0 =A0 =A0one(s); > =A0 =A0} > > =A0 =A0void three() > =A0 =A0{ > =A0 =A0 =A0 =A0two("hello world"); > =A0 =A0} > > > What actually happens here under the hood ? Is this reliable ? > (lifetime of the string object) It won't compile because you assign to a const, so I don't understand the question.