From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2232 invoked by alias); 6 Jun 2006 13:50:29 -0000 Received: (qmail 2223 invoked by uid 22791); 6 Jun 2006 13:50:28 -0000 X-Spam-Check-By: sourceware.org Received: from wr-out-0506.google.com (HELO wr-out-0506.google.com) (64.233.184.226) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 06 Jun 2006 13:50:26 +0000 Received: by wr-out-0506.google.com with SMTP id 69so144742wri for ; Tue, 06 Jun 2006 06:50:24 -0700 (PDT) Received: by 10.64.213.3 with SMTP id l3mr3479302qbg; Tue, 06 Jun 2006 06:50:24 -0700 (PDT) Received: by 10.65.52.16 with HTTP; Tue, 6 Jun 2006 06:50:24 -0700 (PDT) Message-ID: <4b7c18640606060650v7944064dqf39ee460a60b33d1@mail.gmail.com> Date: Tue, 06 Jun 2006 13:50:00 -0000 From: "Trevis Rothwell" To: gcc-help@gcc.gnu.org Subject: extern question MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Google-Sender-Auth: c0e5a1b4b47d3342 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2006-06/txt/msg00045.txt.bz2 Given the files: /* main.c */ #include extern void foo (void); extern void bar (void); extern int larry; int main (void) { printf ("inside main: %d\n", larry); foo(); bar(); return 0; } /* foo.c */ int larry = 42; extern void foo (void) { printf ("inside foo: %d\n", larry); return; } /* bar.c */ int larry; extern void bar (void) { printf ("inside bar: %d\n", larry); return; } ... Compiling and linking all of these together generates a program which gives the following output: inside main: 42 inside foo: 42 inside bar: 42 ... If I add a variable definition to bar.c (so that "larry" is given a value in both foo.c and bar.c) then the compiler complains that the variable is defined more than once, which is true. But, my question is: should I even be allowed to declare "larry" in both foo.c and bar.c ? If so, why is that not seen as a problem? Thanks! -- Trevis Rothwell