473,396 Members | 1,864 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,396 software developers and data experts.

Parameter name can be same as function name???

I just ran across this code at work:
BOOL
main_AddDefaultBenchHeaterPeriods // ???
(
DWORD main_AddDefaultBenchHeaterPeriods // ???
)
{
// ... two dozen lines of code ...

BHSP.obj_id = main_AddDefaultBenchHeaterPeriods; // ???

// ... a dozen lines of code ...

return TRUE;
}
What the devil??? Surely this isn't legal? Can a parameter have
the same name as its function? I'd always thought not. But my
compiler (Visual C++ 6.0) doesn't even give a warning.
The bloke who wrote this file must have had a more bizarre sense of
humor than I'd thought, because he keeps doing really weird things,
such as: a parameter variable which shadows a static variable of
the same name, which shadows a global variable of the same name...
or the case I outline above where the parameter name is the same
as the function name... that sort of thing. Sort of like laying
bear traps in his code for the unwary maintainer. (Ie, me.)
--
Very curious,
Robbie Hatley
Tustin, CA, USA
lone wolf intj atsign pac bell period net
Jun 22 '06 #1
6 3462
Robbie Hatley wrote:
I just ran across this code at work:
BOOL
main_AddDefaultBenchHeaterPeriods // ???
(
DWORD main_AddDefaultBenchHeaterPeriods // ???
)
{
// ... two dozen lines of code ...

BHSP.obj_id = main_AddDefaultBenchHeaterPeriods; // ???

// ... a dozen lines of code ...

return TRUE;
}
What the devil??? Surely this isn't legal? Can a parameter have
the same name as its function? I'd always thought not. But my
compiler (Visual C++ 6.0) doesn't even give a warning.
It is legal. The argument name is contained in a tighter scope
and as such *hides* the function name.
The bloke who wrote this file must have had a more bizarre sense of
humor than I'd thought, because he keeps doing really weird things,
such as: a parameter variable which shadows a static variable of
the same name, which shadows a global variable of the same name...
or the case I outline above where the parameter name is the same
as the function name... that sort of thing. Sort of like laying
bear traps in his code for the unwary maintainer. (Ie, me.)


Yes, unfortunately some see "job security" in it.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 22 '06 #2
Robbie Hatley wrote:
The bloke who wrote this file must have had a more bizarre sense of humor
than I'd thought, because he keeps doing really weird things, such as: a
parameter variable which shadows a static variable of the same name, which
shadows a global variable of the same name... or the case I outline above
where the parameter name is the same as the function name... that sort of
thing. Sort of like laying bear traps in his code for the unwary
maintainer. (Ie, me.)


Yes, a function's scope starts after its name, and, yes, this guy was an
idiot who has impaired your productivity with stupid pranks. Your company
may have unwittingly rewarded him by passing him on to new green-field
projects to afflict.

If you have not made up your complaint quota yet, complain to your boss
that your velocity is slower due to nothing more than petty and malicious
vandalism.

Also, start fixing these things each time you notice them. Read /Working
Effectively with Legacy Code/ by Mike Feathers to learn how.

--
Phlip
Jun 22 '06 #3
"Phlip" <ph*******@gEEEmail.com> wrote in message
news:pa***************************@gEEEmail.com...
Robbie Hatley wrote:
The bloke who wrote this file must have had a more bizarre sense of humor than I'd thought, because he keeps doing really weird things, such as: a parameter variable which shadows a static variable of the same name, which shadows a global variable of the same name... or the case I outline above where the parameter name is the same as the function name... that sort of thing. Sort of like laying bear traps in his code for the unwary
maintainer. (Ie, me.)
Yes, a function's scope starts after its name


Ok, that sort of makes sense.
and, yes, this guy was an idiot
A word two ex-co-workers and I used to use was "BONEHEAD". :-)
(All caps, because we'd #define BONEHEAD and use it in conditional
compilation directives to slice out pieces of his work.)
who has impaired your productivity with stupid pranks.
Yes.
Your company may have unwittingly rewarded him by passing him on to
new green-field projects to afflict.
Actually, he was asked to seek greener pastures elsewhere.
I'm his replacement.
If you have not made up your complaint quota yet, complain to your boss
that your velocity is slower due to nothing more than petty and malicious
vandalism.
I did, but I'm the whole software dept. now. (Downsizing.)
I've been trying to get the company to hire me some fellow programmers,
but the money's too tight right now.
Also, start fixing these things each time you notice them. Read /Working
Effectively with Legacy Code/ by Mike Feathers to learn how.


Thanks for the reference. I think I need that book.

--
Cheers,
Robbie Hatley
Tustin, CA, USA
lone wolf intj atsign pac bell period net
Jun 22 '06 #4
> What the devil??? Surely this isn't legal? Can a parameter have
the same name as its function? I'd always thought not. But my
compiler (Visual C++ 6.0) doesn't even give a warning.


That is pretty bizarre stuff. I'd give him the benefit of a doubt
though and say he's just a lousy programmer rather than saying he's
malicious. Does this guy have any background in Visual Basic? It
reminds me somewhat of how functions work there. Instead of using a
return statement like in C++, you assign the return value to a
quasi-variable with the same name as the function itself.
Jun 23 '06 #5
Victor Bazarov <v.********@comAcast.net> wrote:
Robbie Hatley wrote:
What the devil??? Surely this isn't legal? Can a parameter have
the same name as its function? I'd always thought not. But my
compiler (Visual C++ 6.0) doesn't even give a warning.

It is legal. The argument name is contained in a tighter scope
and as such *hides* the function name.


This is true but it seems to me unnecessary. The function
could be resolved based on the number and types of its arguments;
it would not be hidden by a second function with a different
argument list, so why let a plain variable hide it?

Steve
Jun 23 '06 #6
In message <e7**********@blue.rahul.net>, Steve Pope
<sp*****@speedymail.org> writes
Victor Bazarov <v.********@comAcast.net> wrote:
Robbie Hatley wrote:

What the devil??? Surely this isn't legal? Can a parameter have
the same name as its function? I'd always thought not. But my
compiler (Visual C++ 6.0) doesn't even give a warning.

It is legal. The argument name is contained in a tighter scope
and as such *hides* the function name.


This is true but it seems to me unnecessary. The function
could be resolved based on the number and types of its arguments;
it would not be hidden by a second function with a different
argument list, so why let a plain variable hide it?

What would happen if the "plain variable" _is_ a (pointer to a)
function?

--
Richard Herring
Jun 28 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Douwe | last post by:
I try to build my own version of printf which just passes all arguments to the original printf. As long as I keep it with the single argument version everything is fine. But their is also a version...
5
by: Ram | last post by:
Hi Friends I want to develope a custom control in .net which can be used with any project. I am writing a function in that class which I want to take any object as parameter. For that I have...
5
by: Roy Smith | last post by:
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 /*...
10
by: Tracy | last post by:
Dear all, I have encountered a problem in passing a VARCHAR parameter (which is a list of accepted values) to the IN predicate of a DB2 user-defined function. For example, I have a table...
1
by: NorrYtt | last post by:
I am having a problem with passing a function as a parameter to my DLL so it can call it back with updates. The DLL is written in LabWindows CVI with some #ifdef 'C'-style wrappings. The...
15
by: main() | last post by:
Hi all, When i compile following piece of code, # include <stdio.h> void fun(int val) { int val; /*problem is here*/ printf("%d\n",val);
19
by: George | last post by:
Hi all. How can I check and return an error on a constructor that receives a pointer as a parameter and the parameter is null. Is there any possibility to return an error? or do I have to create...
9
by: serge | last post by:
/* Subject: How to build a procedure that returns different numbers of columns as a result based on a parameter. You can copy/paste this whole post in SQL Query Analyzer or Management Studio...
26
by: aruna.mysore | last post by:
Hi all, I have a specific problem passing a function pointer array as a parameter to a function. I am trying to use a function which takes a function pointer array as an argument. I am too sure...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.