home bbs files messages ]

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,118 of 33,346   
   Dave Harris to Martin B.   
   Re: Why is there no input value optimiza   
   11 Apr 12 21:08:56   
   
   From: brangdon@cix.compulink.co.uk   
      
   0xCDCDCDCD@gmx.at (Martin B.) wrote (abridged):   
   > 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 would not want such a warning. There are too many cases where   
   passing a copy is preferred.   
      
   For example, passing an int by const reference is almost certainly   
   worse for performance. So, probably, is passing a pair of ints, or a   
   pair of pointers. If the warning depends on the size of the object,   
   than making a class use the pImpl idiom could trigger the warning, as   
   could other implementation changes.   
      
   You should consider the issue of aliasing. It may be cheaper to pass a   
   4-int rectangle by const reference, but using it may be more expensive   
   because it's harder for the compiler to be sure it is not changed   
   through an alias.   
      
   Another issue is the need for a standard interface, for   
   polymorphism. Some overrides of a virtual function might change their   
   arguments, and others might not.   
      
   -- Dave Harris, Nottingham, UK.   
      
      
   --   
         [ 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