This is the mail archive of the gcc-prs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

c/529: -Wshadow warns on function prototypes vs. global vars



>Number:         529
>Category:       c
>Synopsis:       -Wshadow warns on function prototypes vs. global vars
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Sep 12 11:36:00 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Joe Zbiciak
>Release:        gcc version 2.95.2 19991024 (release)
>Organization:
>Environment:
Linux 2.2.17, RedHat 6.0
>Description:
When I compile the following code with 'gcc -Wshadow',
I get a warning that 'foobar' shadows a global variable:

    int foobar;
    int func_prototype(int foobar);

This happens most often when #including header files
which use descriptive names in their function prototypes
that also happen to correspond to names of global symbols.
(I see this often with 'index' on systems that define
the function 'index()' in string.h.)

It is obvious that no bug /could/ happen in this case, as
the scope of variable name in the function prototype extends
only to the end of the prototype--it cannot be used as
a variable in any actual code.  Variable names in function
prototypes are intended to provide documentation only,
since it is impossible to use the symbol for any purpose
other than to explain to the human reading the code what
the parameter is used for.  Having these names trigger 
warnings would seem to discourage their widespread use.

Regards,

--Joe
>How-To-Repeat:
gcc -Wshadow shadow.c
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="shadow.c"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="shadow.c"

aW50IGZvb2JhcjsKaW50IGZ1bmNfcHJvdG90eXBlKGludCBmb29iYXIpOwo=

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]