By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,468 Members | 1,453 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,468 IT Pros & Developers. It's quick & easy.

Commented out formal parameter?

P: n/a
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?
Nov 22 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"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.

--
Cy
http://home.rochester.rr.com/cyhome/
Nov 22 '05 #2

P: n/a
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?
Nov 22 '05 #3

P: n/a
"Roy Smith" <ro*@panix.com> wrote in message
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?


It is a function which takes an unsigned int as an argument and returns
void. The name has nothing to do with it. When calling the function you must
provide an unsigned int, either as a constant or as a variable of that type
or a type convertable to that type.

The fact that the argument has no name in the implementation means that the
implementation can't make any use of the argument value.

--
Cy
http://home.rochester.rr.com/cyhome/
Nov 22 '05 #4

P: n/a
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.
Nov 22 '05 #5

P: n/a
Roy Smith wrote:
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 a parameter isn't part of the function's type signature.
That has never been the case, not in the C language, nor in C++.

In C you could write a prototype declaration without naming the
parameters, as in:

extern void foo(unsigned); /* valid ANSI C going back to the 1980's
*/

In C++, it is permissible to omit a parameter name in a function
definition also. This is the means by which the programmer can express
that a parameter is deliberately ignored.

Nov 22 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.