Roy Smith <ro*@panix.com> wrote in
news:ro***********************@reader2.panix.com:
In article <sO******************@twister.nyroc.rr.com>,
"Cy Edmunds" <ce******@spamless.rochester.rr.com> wrote:
"Roy Smith" <ro*@panix.com> wrote in message
news:ro***********************@reader2.panix.com.. . > I've got some legacy code I'm maintaining. There's a method
> declared in the class.h file like this:
>
> void foo(unsigned priority);
>
> and it's implemented as:
>
> void myClass::foo (unsigned /* priority */)
> {
> // body omitted
> }
>
> The parameter priority isn't actually used anywhere in the body (I
> can only
> assume it was at one point in the history of the code).
>
> What I don't understand is how this compiles (and compile it does,
> under 5 different compilers). What does the compiler think the
> signature of the method is?
The name of the formal parameter isn't part of the signature.
OK, that's fair enough, but maybe I phrased my question a little to
explicitly. What, exactly, does the compiler think the definition
means. Is it a function which takes one argument of type unsigned,
with no name? If so, what does it mean to have an argument with no
name?
The compiler thinks it means that the method returns nothing, and takes
an unsigned by value. However since it has no name, it cannot be
referenced (in any sane manner). Usually it's done (the commenting out
of the name) so that the function retains the signature with the unsigned
parameter (perhaps part of a virutal method hierarchy?) but this
implementation doesn't use the parameter. And you don't want your
compiler warning you about an unused parameter.