Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!burl!codas!akgua!sortac!fdg From: fdg@sortac.UUCP Newsgroups: comp.os.minix Subject: Re: More on sh/shar Message-ID: <498@sortac.UUCP> Date: Wed, 3-Jun-87 07:47:30 EDT Article-I.D.: sortac.498 Posted: Wed Jun 3 07:47:30 1987 Date-Received: Fri, 5-Jun-87 04:05:27 EDT References: <1643@encore.UUCP> <581@uokmax.UUCP> Reply-To: fdg@sortac.UUCP (Fred Gant) Organization: AT&T Tech-NS, Atlanta Lines: 75 Summary: Please get your facts straight. In article <581@uokmax.UUCP> rmtodd@uokmax.UUCP (Richard Michael Todd) writes: >In article <1643@encore.UUCP>, paradis@encore.UUCP (Jim Paradis) writes: >> the code for /bin/sh. Getting it to compile was a feat unto itself... >> (seems the MINIX compiler handles globals and externs differently >> from the PC/IX compiler...). >Yep. Actually it's a difference between how UNIX-type linkers (of which >PC/IX's is apparently one) and most everybody else's handle globals. >Under UNIX, you can have multiple files each with a global var. defined, >say: >file foo.c: > int a; >... > >file bar.c: > int a; >... >and the UNIX linker will see the variable declared multiple times in the >modules and allocate space in the result file only once. Most other linkers >consider duplicate variable declarations to be errors. For C programs >on those systems, the global definition can appear in only one file, and >the other files must use extern declarations (e.g. "extern int a;"). >On a side note, I've also gotten the shell to recompile, both under MINIX >and under Aztec C (running the output thru dos2out). I changed all the >offending definitions in sh.h (which gets included in every file) to >read "EXTERN int whatever;" and #defined EXTERN extern in every file except >one. Very minimal changes were needed to get it to compile under Aztec >C after I'd gotten it to compile under MINIX cc. >-------------------------------------------------------------------------- >Richard Todd The "BOOK" is on order; therefore, I do not have the MINIX code yet and can not comment on its handling of globals. I do, however, use C and UNIX daily and can comment on that. In your example, "int a" is not global in either case. It is in fact local to the file that declares it. To be global, it must be declared in a header file, such as sh.h, or be declared outside of the function. An example would be int a, b; /* These are global. */ main() { extern int a, b; /* a & b are globals used by main */ int c, x; /* c, x, & y are local to main */ char *y; ... foo(x,y); ... bar(); ... } foo(w,m) int w; /* w & m are local to foo */ char *m; { extern int a; /* a is a global used by foo */ ... } bar() { extern int b; /* b is a global used by bar int a; ** a is local to bar - Note: the ** compiler and linker should complete ** but lint will warn you that a ** has been redeclared here masking the ** global a. */ ... } This posting is not meant to be critical. I am attempting to clear up a point of confusion. Fred Gant akgua!sortac!fdg AT&T Network Systems