Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!bellcore!decvax!decwrl!pyramid!pesnta!wjvax!brett From: brett@wjvax.UUCP Newsgroups: net.lang.c Subject: Re: Proper use of "extern" ... Message-ID: <714@wjvax.wjvax.UUCP> Date: Fri, 13-Jun-86 12:41:05 EDT Article-I.D.: wjvax.714 Posted: Fri Jun 13 12:41:05 1986 Date-Received: Tue, 17-Jun-86 21:06:50 EDT References: <223@comp.lancs.ac.uk> <132@danews.UUCP> Reply-To: brett@wjvax.UUCP (Brett Galloway) Organization: Watkins-Johnson Co., San Jose, Calif. Lines: 36 In article <132@danews.UUCP> lvc@danews.UUCP (Larry Cipriani) writes: >My understanding of extern is that it simply declares the >object in question... > >I often put ALL of the declarations in one header file, and include >it in all the other files. This is a matter of style, and I recognize >its weaknesses, but I like it better than all the alternatives. By the >way, extra, redundant, or unnecessary externs are allowed and don't matter, >at least on my C compiler. Harbison & Steele say only that this property is true of the 4.2bsd C compiler. Speaking of its treatment of extern, they say: "If the identifier so declared is never actually used, the compiler will not issue an external reference to the linker" (H & S, p. 82) I find this feature very useful, since I often generate a library which one associated include file that contains external references to all the routines therein. This frees the user of my library from having to declare all the routines himself (at least those that don't return in). This is a minor advantage. A MAJOR advantage is that it also lets me transparently convert some routines to macros, or back again. If the user had declared them, I could not convert a routine to a macro without REMOVING all the user's declarations. 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, no matter how many routines he actually used. This would be annoying. My question is -- how general is this feature? Is it true of AT&T SYSV? Is it true of some of the common PC C compilers? Other C compilers? ------------- Brett Galloway {pesnta,twg,ios,qubix,turtlevax,tymix,vecpyr,certes,isi}!wjvax!brett