Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!panda!enmasse!rclex!harvard!seismo!umcp-cs!chris From: chris@umcp-cs.UUCP (Chris Torek) Newsgroups: net.lang.c Subject: Re: Proper use of "extern" ... Message-ID: <2033@umcp-cs.UUCP> Date: Mon, 16-Jun-86 14:52:44 EDT Article-I.D.: umcp-cs.2033 Posted: Mon Jun 16 14:52:44 1986 Date-Received: Wed, 18-Jun-86 04:10:37 EDT References: <223@comp.lancs.ac.uk> <132@danews.UUCP> <714@wjvax.wjvax.UUCP> Organization: Computer Sci. Dept, U of Maryland, College Park, MD Lines: 43 >In article <132@danews.UUCP> lvc@danews.UUCP (Larry Cipriani) writes: >>... extra, redundant, or unnecessary externs are allowed and don't >>matter, at least on my C compiler. In article <714@wjvax.wjvax.UUCP> brett@wjvax.UUCP (Brett Galloway) writes: >Harbison & Steele say only that this property is true of the 4.2bsd C >compiler. ... > > "If the identifier so declared is never actually used, the compiler > will not issue an external reference to the linker" (H & S, p. 82) > >... However, if the above feature is not present, each external >reference in the include file causes the subroutine to be linked in, >with the result that anybody that uses my include file and my library >gets the ENTIRE library linked in .... > >... how general is this feature? ... Is it true of ... Other >C compilers? I submit that any compiler that does not have this `feature' is, if not broken, at least being rather dumb. Consider: all a compiler need do is note at an `extern' declaration that the variable or function is presently unused, but semantically valid. At the first actual reference to the variable, the compiler can generate whatever linker commands (if any) are required to make the variable or function available at run-time. In this manner, a C source file consisting entirely of `extern' declarations: extern int i; extern double d; extern char *cf(); would generate no code whatsoever. For some reason, not all compiler writers seem to have realised this; in such cases, I grit my teeth and fiddle with the source code, but also complain vociferously. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1516) UUCP: seismo!umcp-cs!chris CSNet: chris@umcp-cs ARPA: chris@mimsy.umd.edu