cppannotations/annotations/contributions/FAQ
Frank B. Brokken 777b182edd Moved all files but 'excluded', 'sf', and 'sourcetar' to ./annotations
This allowed me to standardize the sourcetar and sf/* scripts: the base
    directory (containing ./git) is now empty, except for maintenance scripts,
    while the source files and build scripts of the annotations are stored in
    a subdirectory of their own.
2013-05-29 20:44:08 +02:00

32 lines
1.1 KiB
Text

1. Too many consts?
--------------------------------------------------------------------------
1. Too many consts?
> int compareWrapper(void const *p1, void const *p2)
> {
> return
> Person::compare
> (
> static_cast<Person const *const *>(p1),
> static_cast<Person const *const *>(p2)
> );
> }
> Isn't it const *const * one const * too much?
To answer your question: well, you could omit one const, but it blurrs the
intention. Person::compare's prototype is
int Person::compare(Person const *const *p1, Person const *const *p2);
which mentions two consts: the parameters are pointers to pointers should not
be modified nor should be modified what these latter pointers point to.
Hence two consts in the static cast. The last const matches the const in void
const *, and the first const matches the intention of Person::compare's
function. Leave out the last const and the compiler complains, leave out the
first const and the compiler will pass a non-const pointer to a const *
parameter, which by itself is OK, but blurrs your intention.