Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!mit-eddie!think!ames!lll-tis!elxsi!len From: len@elxsi.UUCP Newsgroups: comp.os.minix Subject: Re: Global variables (was Re: More on sh/shar Message-ID: <408@elxsi.UUCP> Date: Fri, 5-Jun-87 20:51:57 EDT Article-I.D.: elxsi.408 Posted: Fri Jun 5 20:51:57 1987 Date-Received: Sat, 6-Jun-87 20:24:12 EDT References: <1643@encore.UUCP> <581@uokmax.UUCP> <498@sortac.UUCP> <587@uokmax.UUCP> Reply-To: len@elxsi.UUCP (Len Mills) Organization: ELXSI Super Computers, San Jose Lines: 30 In article <587@uokmax.UUCP> rmtodd@uokmax.UUCP (Richard Michael Todd) writes: >In this example, the 'a's in both files are global variables. On UNIX >systems, compiling with "cc foo.c bar.c" will succeed and in the resulting >program both modules, when referring to 'a' refer to the same memory >location, thus the program will print out: >5 >7 >On non-UNIX systems, the linker will complain about multiple definitions >of the symbol a. >Note that the functions 'main' and 'bar' above do not have to declare >within the function body that 'a' is extern, as you did in your example >code: Not necessarily true. There are numerous approaches to the handling of the consistency among the declaration of the same external name or top-level-declaration in different files. The example in the referenced article assumes BSD-style unix systems, as 4.2BSD takes a mixed strategy approach, and in effect merges the declarations at link time, in the manner of a FORTRAN "common" declaration. ATT-style systems do not take this approach, and will absolutely cause errors. For a better explanation than I could manage without plagarism, see section 4.8 of Harbison & Steele, _A_C_Reference_Manual_, Prentice-Hall, 1984. Let's not argue over whether or not BSD and ATT are both UNIX systems. The above is not intended as a flame, just the facts, folks. Len