Path: utzoo!attcan!uunet!mcvax!philmds!leo From: leo@philmds.UUCP (Leo de Wit) Newsgroups: comp.lang.c Subject: Re: extern question Message-ID: <544@philmds.UUCP> Date: 2 Jul 88 08:46:30 GMT References: <4182@pasteur.Berkeley.Edu> Reply-To: leo@philmds.UUCP (Leo de Wit) Organization: Philips I&E DTS Eindhoven Lines: 45 In article <4182@pasteur.Berkeley.Edu> faustus@ic.Berkeley.EDU (Wayne A. Christopher) writes: |Is the following acceptable C code: | | extern int foo(); | | bar() | { | int (*bla)() = foo; /* CASE 1 */ | | foo(); /* CASE 2 */ | } | | static int | foo() | { | ... | } | |In other words, should extern be interpreted as "possible forward |reference" (the way I'm using it), or "externally defined symbol"? All |the compilers I have used handle case 2 ok, but one couldn't deal with |case 1. Shouldn't they both work the same? | |From an aesthetic viewpoint, I like to use extern anywhere I declare |something but don't define it. I think writing | | int foo(); | |for static functions is not as clear. | | Wayne Indeed. You should write static int foo(); This is - in my point of view - the only correct forward declaration. It is also better from aesthetic point of view, in that it does use the correct storage type. Notably the Lattice C compiler is rather strict regarding storage classes / extern definitions; I like that. As for extern declarations, they typically belong in a header file (the one that belongs to the module defining the extern function / variable, i.e. is the - outgoing - interface of that module to the outside world). Leo (that's the way I C it; don't blame me for being stubborn 8-).