Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/5/84; site danews.UUCP Path: utzoo!watmath!clyde!cbosgd!danews!lvc From: lvc@danews.UUCP (Larry Cipriani) Newsgroups: net.lang.c Subject: Re: Proper use of "extern" ... Message-ID: <132@danews.UUCP> Date: Mon, 9-Jun-86 16:03:54 EDT Article-I.D.: danews.132 Posted: Mon Jun 9 16:03:54 1986 Date-Received: Thu, 12-Jun-86 03:00:27 EDT References: <223@comp.lancs.ac.uk> Organization: AT&T Bell Labs, Columbus OH Lines: 43 My understanding of extern is that it simply declares the object in question. That is, the compiler is told what type the object is. I don't know of any other use for extern. When you define the object, you tell the compiler the type, and allocate space for it, etc. > A file has two functions in it, "f" and "g", thus > > static void f() > { > g(); > } > > static void g() > { > } > > f uses g and g is declared after f (I know we can put g before > f and the following is no longer applicable but ...). > > At the top of this file do we put > a) static void g() or > b) extern void g()? (extern static must be meaningless). Again, I don't mean to be picky, but f and g are "defined" here, not "declared". Any book that doesn't follow this convention is wrong. > My understanding (this varies with the book you read) of "extern" is that > it means the object is declared "later in this file or in another file" in > which case I vote for (b). Is this right? Yes, but for the wrong reason. 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. -- Larry Cipriani AT&T Network Systems danews!lvc "Nothing is worse than an itch you can never scratch."