This is the mail archive of the gcc-bugs@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]
Other format: [Raw text]

[Bug c/45977] New: "warning: 'i' initialized and declared 'extern'" is spurious


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45977

           Summary: "warning: 'i' initialized and declared 'extern'" is
                    spurious
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: konrad.schwarz@siemens.com


Created attachment 22020
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=22020
file "external.c", a short test case exhibiting the problem

Given the attached source file, GCC (powerpc-eabi-gcc.exe (Sourcery G++ Lite
4.4-79) 4.4.1), invoked as:
powerpc-eabi-gcc -te500v1 -mcall-sysv-noeabi -MMD -Wno-parentheses      -c -o
ex
ternal.o external.c

reports:
external.c:3: warning: 'i' initialized and declared 'extern'

The relevant lines in the file are:

# if    1
static int i;
# endif

extern int i = 3; 

The warning occurs irrespectively whether the # if 1 is changed to # if 0.

Standard C gives the above code a well defined meaning.  The following
reference is from the C89 specification:

6.1.2.2, Linkage of Identifiers:
If the declaration of an identifier for an object or a function contains the
storage-class specifier <b>extern</b>, the identifier has the same linkage as
any visible declaration of the identifier with file scope.  If there is no
visible declaration with file scope, the identifier has external linkage.

Thus, the primary meaning of "extern" for external definitions (that is,
definitions with file scope) is to use whatever linkage specification is
already in force.  Only if no linkage specification has been specified
previously does "extern" mean assign external linkage.

This is in contrast with "static", which means assign internal linkage, and no
storage-class specifier, which means external linkage for objects (but means
the same thing as "extern" for functions, i.e., use existing linkage if
possible).

6.1.2.2 goes on to specify that only one type of linkage may be specified for a
n identifier in a translation unit.

Consider a code generation scenario using the C preprocessor (include
directives), where a generic code generation component is being employed. 
Standard C allows a design where the (documented) definitions supplied by the
component are marked "extern", giving the user of the component the ability to
override the linkage by providing a tentative definition marked "static" before
including the component's header file.

The warning emitted by GCC undermines this design.

So what I'd like is for:
* this warning to be turned off by default
* (possibly) enable this warning with -Wextra


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