On Wed May 25, 2005 at 12:21:35 +1000, Peter Miller wrote:
>On Wed, 2005-05-25 at 09:20 +1000, Benno wrote:
>> This will warn about the name of an argument in a function
>> *declaration*, shadowing a global.
>
>I try very hard to make the parameter names in the function prototype
>match the parameter names in the function definition.  This makes the
>Doxygen documentation more useful, and there's less to remember.

Agree.

>Plus one more rule: always include the .h with the interface defintion
>in the .c implementing that interface.  This lets the compiler detect
>incorrect proptotype vs defintion (i.e. horrendously hard to find bugs).

Agree.

>In the context of the above two paragraphs, the error is not meaningless
>when compiling the function definition.  Fixing the function definition
>to use a different name (because of -Wshadow) implies changing the
>function prototype to match.  Viola, no more "meaningless" warnings.

Doesn't fix the problem.  The implementation of the functions don't
include.  the header with the shadowing. A more full example follows:

### foo.h

int foo(int bar);


### foo.c

#include <foo.h>

int foo(int bar) { return bar * 2; }


/* Foo.c compiles fine w/o shadow warning! */

### bar.h

int bar(int x);

### bar.c

#include <bar.h>

int bar(int x) { return x / 2; }


/* bar.c compiles fine w/o shadow warnings! */

### magical_program.c

#include <bar.h>
#include <foo.h>

/* totally different program written by someon else, uses
  foo.h and bar.h and now gets -Wshadow errors!!! */

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

Reply via email to