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 Newsgroups: comp.lang.c++ Subject: Re: removing constness of a true const Date: Sat, 16 Jul 2011 08:36:18 +1200 Lines: 26 Message-ID: <98bmo4FdjcU1@mid.individual.net> References: <1e55c267-2789-498c-a5a1-f56e499336e5@z12g2000yqj.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net s4deOrfYYfkJ24UgvXxUrAow3SbVIkYldKv5s5ITLMrhBLCqnM Cancel-Lock: sha1:gcZjkZbOBrxJqUzHAI4xNh/AxCc= 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: Xref: x330-a1.tempe.blueboxinc.net comp.lang.c++:7842 On 07/16/11 04:04 AM, Balog Pal wrote: > "Victor Bazarov" >>> const std::pair foo = std::make_pair(1,2); >>> >>> is any less const than two separate ints? Or that overwriting them is >>> less UB? >>> >>> I'd be very disappointed if today's compilers would not put that pair in >>> the 'const' segment and fiddling with it would not cause a crash. >> >> 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? > > Why should it be initialized "at runtime"? Unless you have volatiles > involved, what is pretty rare, the standard mandates that initialisation > happened before you use. Not telling how much before. It can be done at > compile time, if the compiler can guess the result. Like in the above case. Maybe it could, but do you know a case where it is? The two compilers I tried (Sun CC and g++) build the object in a static constructor. Oh the joys of UB.... -- Ian Collins