Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.c++.moderated    |    Moderated discussion of C++ superhackery    |    33,346 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 32,113 of 33,346    |
|    =?ISO-8859-1?Q?Daniel_Kr=FCgler?= to All    |
|    Re: Why is there no input value optimiza    |
|    10 Apr 12 23:29:25    |
      From: daniel.kruegler@googlemail.com              Am 10.04.2012 23:38, schrieb Martin B.:       > On 10.04.2012 20:00, Ulrich Eckhardt wrote:       [..]       >> [..] Also, any function can cheat and const_cast, so a       >> calling function must not assume that the call doesn't modify the       >> passed object. ...       >       > Interesting point. Who at which level is required to assume that       > something passed by const-ref is modified by the callee?              Any object that is not a const object may be modified. In most daily       scenarios arguments provided to functions are not really const objects,       therefore a "const &T" does not really protect from modification. Worse,       in the current standard it is not even clear whether an object with       dynamic storage duration (e.g. created by new expressions) can be a       const object. The intention is that they can be, see              http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1428              Back to your last question: If you define a const object and provide       this object to any function (by reference or pointer), you can rely on       the assumption that code that would attempt to modify the object would       enter undefined behaviour. But as Ulrichs response implied: Compilers       would have a hard time to track any possible modifications of objects       that are referenced as const objects. For this reason they usually do       not optimize away objects provided by reference.              HTH & Greetings from Bremen,              Daniel Krügler                     --        [ See http://www.gotw.ca/resources/clcm.htm for info about ]        [ comp.lang.c++.moderated. First time posters: Do this! ]              --- SoupGate-Win32 v1.05        * Origin: you cannot sedate... all the things you hate (1:229/2)    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca