Re: extern
- From: Stephen Sprunk <stephen@xxxxxxxxxx>
- Date: Tue, 09 Sep 2008 14:36:44 -0500
Bill Cunningham wrote:
Is extern used to externalize functions as well as variables? If I have this function,
int num(int n);
Should it be declared as above in the file in which main is called and compiled with the file that contains num's body? Or should it be declared as this,
extern num (int n);
The usual convention is that you would put the declaration ("int num(int n);") in a header (.h) file and then include that header file into any source (.c) file that called that function plus the source file that actually defined it.
"extern" is the default for function declarations, so it's not necessary. If you wanted to share a variable across multiple source files (a "global" variable), though, you would need the "extern" on its declaration in the header file.
S
.
- Follow-Ups:
- Re: extern
- From: Bill Cunningham
- Re: extern
- References:
- extern
- From: Bill Cunningham
- extern
- Prev by Date: Re: extern
- Next by Date: Re: UNIX, C, Perl
- Previous by thread: Re: extern
- Next by thread: Re: extern
- Index(es):
Relevant Pages
|