passing POD by value with const qualifiers. Silly or not?
Woebbeking at kde.org
Fri Feb 22 19:41:49 GMT 2008
On Friday 22 February 2008, Stefan Teleman wrote:
> On Fri, Feb 22, 2008 at 8:28 AM, André Wöbbeking <Woebbeking at kde.org>
> > Did you try it? According to the C++ standard e.g.
> > void foo(int);
> > void foo(const int);
> > are equivalent.
> Tried it and dealt with it many many times.
> Overloadable declarations
> [ ... ] const and volatile type-specifiers buried within a parameter
> type specification are significant and can be used to distinguish
> overloaded function declarations. [ ... ]
Either the context of that paragraph changed or you oversaw it. In
ISO/IEC 14882:1998 it is:
Only the const and volatile type-specifiers at the outermost level of
the parameter type specification are ignored in this fashion; const and
volatile type-specifiers buried within a parameter type specification
are significant and can be used to distinguish overloaded function
declarations. In particular, for any type T, “pointer to T,” “pointer
to const T,” and “pointer to volatile T” are considered distinct
parameter types, as are “reference to T,” “reference to const T,”
and “reference to volatile T.”
> One could argue that overloading on the const or volatile type
> specifier was intended for pointer or reference types only [hi,
> comp.std.c++.moderated!], but Sun Studio has enforced the overloading
> distinction between void foo(int) and void foo(const int) since i can
> The question still remains (in my mind): why is void foo(const int)
> useful ? It's not like there are any amazing assembler optimizations
> possible when saying void foo(const int) as opposed to just void
As I wrote before, it isn't useful in the API.
More information about the kde-core-devel