Re: Usage of pre-processor macro.
On 2010-06-30 15:57:34 -0400, ?? Tiib said:
On 30 juuni, 22:40, Pete Becker <p...@versatilecoding.com> wrote:
On 2010-06-30 13:43:03 -0400, Tiib said:
On 30 juuni, 20:11, Pete Becker <p...@versatilecoding.com> wrote:
On 2010-06-30 10:50:46 -0400, Christian Hackl said:
Pete Becker ha scritto:
On 2010-06-30 07:02:44 -0400, Helge Kruse said:
If you omit the UNREF_PARAM, the compiler may warn about unreferenced
parameter(s). The macro creates code where the parameter is assignedto
itself. This doesn't hurt and is optimized away if optimization is
enabled.
Turn off stupid warnings.
I often see this warning labelled as "stupid", but have you never had a
situation in which, by accident, you really were using the wrong
variable in the function? Something along the lines of:
int MyClass::calculate(int x, int y)
{
return complicatedCalculation(x, x); // bug, should be x, y
}
Are some "false positives" of this warning a reason to give away a
chance to automatically detect such bugs?
Yes. If you've written good unit tests, ignoring a function argument
that matters will always be detected.
Unit tests do not usually test design problems, so how they help?
They help because *using the wrong name variable* (emphasis added) is
not a design problem, but a coding problem.
There they detect same coding problem as that warning in different
ways. Lets say someone does code there something and makes such a
coding error. Will he repair it more quickly if he see both
diagnostics or only one of them? IOW i do not still get why you
suggest to silence it globally.
Because not using a function parameter is a legitimate coding
technique, and having to sort through warnings about it to figure out
whether there's a genuine error, or adding extraneous code in order to
suppress bogus warnings, is a distraction. But perhaps I assume too
high a degree of professionalism in programmers; if you feel that you
can't write adequate unit tests, or won't run them, then perhaps you
need more help in identifying a low-probability error, and sorting
through the extra noise is worthwhile for you.
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)