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,107 of 33,346    |
|    Martin B. to rossmpublic@gmail.com    |
|    Re: Why is there no input value optimiza    |
|    10 Apr 12 10:57:56    |
      0c8ea3c0       From: 0xCDCDCDCD@gmx.at              On 10.04.2012 11:18, rossmpublic@gmail.com wrote:       > I have a very simple question that I have been unable to find a       > satisfactory answer. The question is why do I need to manually       > optimize my functions using const references?       >       > For example:       >       > // Optimized passing of string parameter       > Widget(std::string const& name);       > ...       > // Non-optimized passing of string parameter       > Widget(std::string name);       > ...       >       > I understand that with the latter notation there is an additional       > copy involved on most compilers, but why is that exactly?       > Why is it that the compiler (as smart as it is today) is unable to       > optimize away the additional copy?       >       > Why ...       >       > I attended the Going Native 2012 conference, and even here we were       > reminded to pass strings by reference. ...                     I will not go into your snipped "why" question, because probably I would       make a mess of it.              However, what I would like to raise as a QOI question is, why can't we       have (or do we?) a proper compiler warning when the compiler detects       that the passed-by-value parameter isn't modified at all and really       should have been passed by const-reference?              I'm currently working with VC++ and I'm not aware of any help by the       compiler in this area.              Is this something static analysis tools check? What about Clang or gcc,       do they offer something similar?              cheers,       Martin              --       Good C++ code is better than good C code, but       bad C++ can be much, much worse than bad C code.                      [ 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