473,395 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Commented out formal parameter?

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
5 1681
"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
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
"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mysooru | last post by:
Hi All, One of the ATL class..... template <class Base> class CComObject : public Base { public: typedef Base _BaseClass;
18
by: PC Datasheet | last post by:
On 10/31 I responded to a post, "How Do I Set Up A Small Business Database", by 78cryj in the MS.Public.Access.TablesDesign newsgroup . The poster requested help " ...if you know any database...
1
by: Jim Heavey | last post by:
Hello, I thought I was loosing my mind. I had a page which was working perfectly fine until I decided to try to add a control to a footer line in code. So I took the Validation control which was...
0
by: erktek | last post by:
Hi! It is clear that when we try to pass a one dimentional array to a function we use int* such as void display(int *LocalAarray) { ...... }
3
by: christianlott1 | last post by:
I wouldn't have brought this up except that a friend had a similar problem as well. Situation: Code works fine for months, then suddenly breaks. In my case the code broke on a piece of...
2
by: tawright915 | last post by:
Ok so here is my regex (--.*\n|/\*(.|\n)*?\*/). It finds all comments just fine. However I want it to return to me all strings that are not commented out. Is there a way to exclude the comments...
3
by: =?Utf-8?B?UmljaGFyZA==?= | last post by:
Hi, I removed some functionality from an ASP.NET 2 webpage by deleting the input ior textbox control from the page's code. Then I commented out the JavaScript function on the same page that...
5
by: =?Utf-8?B?RGF2aWQgTGV2aW5l?= | last post by:
This is really more of a "why was C# designed this way?" type of question. Hope this is the write forum for this question. Given the following : class Base1 { public int i; } struct Base2...
0
by: TeenaRoz | last post by:
Hi, I am using axis jars to convert my java classes into wsdl for API purpose. I notice that, instead of generating the parameter names same as what my method accepts, I am getting it as...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.