`>On Wed May 25, 2005 at 07:10:00 +1000, Erik de Castro Lopo wrote:
>Benno wrote:
>
>> My main work around for this was having function declarations in
>> header files not specify the name of arguments, to avoid potential
>> spurious clashes. However this means that I can't use doxygen, which
>> relies on the name of arguments to document the functions.
>
>Wouldn't it be better to just rename the function parameters?
>I use indx instead in index all over the place.
>
>Once you fix the warnings from the initial addition of -Wshadow
>it rarely bites again and there is one more potential bug you
>don't have to worry about.
That is what I've been doing, but it in fact sucks more than just
shadowed function names. (And gcc is dumb wrt index, since I don't
even use strings.h anywhere... but that is another matter).
What really sucks is that function argument names come up as shadowed,
which really screws over your namespace. E.g:
""" (foo.h)
int foo(int bar);
"""
""" (bar.h)
int bar(int x);
""" (foo.c)
#include <bar.h>
#include <foo.h>
"""
This will warn about the name of an argument in a function
*declaration*, shadowing a global. There is no logical reason for gcc
to bitch about that since they are totally different namespaces. E.g:
foo.h and bar.h can be from totally separate libraries and they need
to work out somehow so that the argument names to their function don't
clash. Too silly.
My solution to this, which I have been using until now is to not have
argument names in function declarations. (Since they aren't strictly
needed.) However this means you lose a nice self-documentation in the
header files. And more annoyingly means I can't use doxygen to
document them. I guess I could use the standard C namesapce hack, and prefix
them with the name of the library e.g: int foo(int foo_bar); but that
seems kind of crap.
(Note that -Wall catches the biggest problem class of shadowed variables, where
a local shadows
an argument. E.g:
int foo(int x) {
int x;
}
Will be picked up by -Wall, even without -Wshadow.
(That said I'm still quite loath to remove it given that obvious advatanges of
automated
static analysis.)
Cheers,
Benno
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html