Xref: utzoo comp.lang.c:25862 comp.std.c:2452 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!umich!samsung!usc!apple!snorkelwacker!spdcc!ima!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c,comp.std.c Subject: Re: extern int f(); VS int f(); Keywords: Storage Classes, External References Message-ID: <15929@haddock.ima.isc.com> Date: 12 Feb 90 20:53:40 GMT References: <2912@hcx1.SSD.CSD.HARRIS.COM> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Cambridge, MA 02138-5302 Lines: 30 Doug already posted the details, but it might not be clear what the answer is to the original question. In article <2912@hcx1.SSD.CSD.HARRIS.COM> brad@SSD.CSD.HARRIS.COM (Brad Appleton) writes: >Are the following function declarations equivalent? >(1) extern int foo(); >(2) int foo(); Yes. They are completely identical in any sane compiler. >I was just asked this question and I thought I knew a precise answer but >I find that I am a little fuzzy on this one! I thought (2) is like a >"forward" declaration in Pascal and that the only difference between these >two is that If I use (2) then I may define the function "foo" (give it >a body) later on in the same file. Is this right? With either spelling, the actual definition for the function can appear in either the same file or in a different file. (Some people prefer to use "extern" for functions defined in separate files and omit "extern" for forward declarations; this is a matter of taste.) But it must be a global function. To forward-declare a static function%, you should use "static int foo();". When dealing with objects rather than functions, the situation gets worse. Karl W. Z. Heuer (karl@ima.ima.isc.com or harvard!ima!karl), The Walking Lint ________ % There may be some compilers that won't let you forward-declare a static function. If you have to deal with such a beast, it's probably best to sort the function definitions (if they aren't mutually recursive) or promote one of them from static to global so you can forward-declare it.