extern is used in multi file projects and is used to saythe following to
the compiler:
"This variable is declared in another file, when you are linking look
for it and link it in".
E.g.
--File1.cpp--
int my_global_var = 5;
int main()
{
...
}
--end File1.cpp--
--File2.cpp--
extern int my_global_var;
void some_funct_that_uses_global(void)
{
...
}
--end File2.cpp--
Now anything that uses my_global_var in file2 is using the same variable
that the functions in file1.cpp are using.
Any type of variable can be used with extern (class, struct, union, etc)
even functions. For functions they are seldom (if ever) used because
functions are automatically shared throught all files in a program, so
putting extern is redundant.
Signed
David McKen
Noorez Kassam wrote:
> What does the keyword "extern" do?
>
> _________________________________________________________________
> Add photos to your messages with MSN Premium. Get 2 months FREE*
> http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&DI=1034&SU=http://hotmail.com/enca&HL=Market_MSNIS_Taglines
>
>
>
>
> -------------------------------------------------------
> This SF.Net email sponsored by Black Hat Briefings & Training.
> Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital
> self defense, top technical experts, no vendor pitches, unmatched
> networking opportunities. Visit www.blackhat.com
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|