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/40661] New: Incorrect warning "defined but not used"


=========== Begin complete code ===========
#include <stdio.h>

static int y = -1234; 

int main(void)        
{                     
  extern int y;       
  printf("%d\n", y);
  return 0;
}   
=========== End complete code ===========

command line: gcc -W -Wall test.c

Output:
test.c:3: warning: 'y' defined but not used


As you can see "y" is defined (in line 3), then declared in line 7
and used in line 8. The program also executes correctly.

The use of an "extern" storage class specifier is a bit unusual
but perfectly legal (See ISO/IEC 9899:1999 chapter 6.2.2, paragraph 4).

If anything a warning about this slightly obscure construct might be in OK, 
but not about an unused variable.

I would have liked to verify with a newer GCC version but haven't 
got any available here, sorry.


-- 
           Summary: Incorrect warning "defined but not used"
           Product: gcc
           Version: 3.4.4
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ahelm at gmx dot net
  GCC host triplet: i686-pc-cygwin
GCC target triplet: i686-pc-cygwin


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


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