[Exceptional C++ Style] Exceptional C++ Style - Item 24: Cons tantOptimization

Hammond, Peter peter.hammond at amsjv.com
Thu Jan 27 05:44:21 EST 2005




> -----Original Message-----
> From: Balog Pal [mailto:pasa at lib.hu]
> Sent: 24 January 2005 17:07
> To: effective-cpp at accu.org
> Subject: Re: [Exceptional C++ Style] Exceptional C++ Style - Item 24:
> ConstantOptimization
>
<big snip> 
> 
> An old guideline said const  (non-ref) params belong to the 
> *impelmentation 
> details*. So in headers and function interfaces const shall 
> be omitted (it's 
> discarded by the compiler anyway). And the implementation can 
> insert cont at 
> will if it feels like it.
> 

I was wondering about this in the context of coding standards recently. In
Exceptional C++ (item 43) Herb remarks that const on a value parameter is
pointless, and when I see it in a header it worries me: it is a sign that
someone may have misunderstood const, or pass-by-vlaue, or both. On the
other hand, having the constness of the argument enforced in the
implementaion can be very useful. The obvious way to solve it is to leave it
in the implemtation, but remove it from the definition, as the guideline
above. However, the difference between declaration and definition would seem
to be a source of confusion for many. Has anyone got any experience of this
kind of guideline and whether in practice it helps or confuses?

Ta,
Pete.

[ *** LongSig auto truncated *** ]



More information about the Effective-cpp mailing list