Article View: comp.lang.c.moderated
Article #2129Re: "extern" and function declarations
From: Ari Lukumies
Date: Fri, 01 Mar 1996 15:34
Date: Fri, 01 Mar 1996 15:34
32 lines
1943 bytes
1943 bytes
Carl Laurence Gonsalves wrote: > > Is there any difference in the meaning between the following two > declarations? > > extern int foo( void ); > int foo( void ); > > In other words, is "extern" ever necessary before a function prototype? > I've never used "extern" for function declarations before, and recently > I've seen some code which uses extern in front of the prototypes in the > headers. I'm wondering, is it okay to leave out extern, or is there a > possibility that some compiler/linker will have problems if I leave it > out? > The scope modifier 'extern' is used to indicate that a particular function does not exist in the currently compiled source module, but in another one. By default, if you leave out 'extern' and 'static', the functions are compiled so, that in the produced object code they are 'published', ie. that another object module may call them and the linker can find them and fix the calling address. If you declare a function 'static', many compilers do not include the publishing information for them, so the linker cannot find them. If your functions are called from within one module only, declaring them 'static' reduces the amount of object code produced. Some compilers accept the case where you declare a function 'extern' everywhere, but that is not a good practice, if you consider someone who has to maintain your code afterwards. Later, AriL -- All my opinions are mine and mine alone.
Technical Details
Message-ID:
<4h75dc$4nv@solutions.solon.com>Path:
arc1-ca.pugleaf.net!solon.com!not-for-mailReferences:
<4h2s5p$ok@solutions.solon.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail From: Ari Lukumies <aril@cmt.lpr.mail.carel.fi> Newsgroups: comp.lang.c.moderated Subject: Re: "extern" and function declarations Date: 1 Mar 1996 09:34:04 -0600 Organization: Carelcomp Forest Sender: clc@solutions.solon.com Approved: clc@solutions.solon.com Message-ID: <4h75dc$4nv@solutions.solon.com> References: <4h2s5p$ok@solutions.solon.com> NNTP-Posting-Host: solutions.solon.com X-Mailer: Mozilla 2.0 (WinNT; I)