From owner-freebsd-hackers Mon Jul 3 14:22:36 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from salmon.maths.tcd.ie (salmon.maths.tcd.ie [134.226.81.11]) by hub.freebsd.org (Postfix) with SMTP id E478137BFD1 for ; Mon, 3 Jul 2000 14:22:31 -0700 (PDT) (envelope-from dwmalone@maths.tcd.ie) Received: from walton.maths.tcd.ie by salmon.maths.tcd.ie with SMTP id ; 3 Jul 2000 22:22:30 +0100 (BST) To: Poul-Henning Kamp Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: Global variables defined several times. In-reply-to: Your message of "Mon, 03 Jul 2000 22:43:10 +0200." <8739.962656990@critter.freebsd.dk> X-Request-Do: Date: Mon, 03 Jul 2000 22:22:30 +0100 From: David Malone Message-ID: <200007032222.aa41540@salmon.maths.tcd.ie> Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > In message <200007032140.aa37554@salmon.maths.tcd.ie>, David Malone writes: > >I've just noticed that usr.bin/ftp/ftp_var.h defines a large > >selection of global variables, and then this header file is included > >in multiple C source files. > > > >I thought this should lead to one copy of the global varible per > >source file, and then a warning or error at link time due to symbols > >being defined multiple times. This doesn't seem to be the case with > >the toolchain - you seem to get one copy of each variable for the > >final linked unit. > This is called "common" variables. They're documented with that > behaviour in the old and new testament. In the K&R1 I have to hand, the last line of page 76 and top of page 77 say: If the lines int sp; double val[MAXVAL]; apprar outside any function, they \emph{define} the expernal variables sp and val... Further down page 77: There must be only one \emph{definition} of an external variable among all the files that make up the source program; other files may contain extern declarations to access it. I can't find my second edition at the moment. This behavior is commented on in the C FAQ as something the ANSI standard describes as a common extension. (http://www.eskimo.com/~scs/C-faq/q1.7.html) It also seems to suggest it is mostly a Unix thing. David. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message