Actually, in C, everything is public in scope unless you declare it
otherwise. (Obviously, I'm not talking about data declarations in
functions.) Unless you explicitly declare something "static", giving it
file scope, it will have "external linkage". This already prevents the
reuse of the name, since most linkers will complain about two identical
names.
All the "extern" does in a function or variable declaration is say that
something exists somewhere else, probably not here. Actually, in a function
declaration, the "extern" is assumed if there is nothing else there.
As far as style goes, I try to keep my use of globals to a minimum. I'm not
too fond of variables with file scope either, though. Sometimes, though,
you've just gotta. (Hey, Palm Guys, how about four bytes of user storage in
the form structure! Let me get rid of a lot of my statics, please.)
Good luck,
George
----------
>From: "Ted Lowery" <[EMAIL PROTECTED]>
>To: "'[EMAIL PROTECTED]'" <[EMAIL PROTECTED]>
>Subject: RE: extern globals and procedures
>Date: Wed, Oct 27, 1999, 11:58
>
> Agreed.
>
> But when I was in school, casting everything extern makes everything public
> in scope. not only was I taught that was bad programming practice, but it
> means you can't reuse or overload function names.
>
> I thought maybe there was a programmatic reason for casting everything
> extern. I guess it's just the convention of the programmer who wrote the
> starter app.
>
> Cheers, Ted
>
>> -----Original Message-----
>> From: Aaron Ardiri [SMTP:[EMAIL PROTECTED]]
>> Sent: Tuesday, October 26, 1999 11:22 AM
>> To: [EMAIL PROTECTED]
>> Subject: Re: extern globals and procedures
>>
>> > I notice in most of the sample code, every global variable and
>> > function/procedure is declared extern. I'm not used to coding like
>> this,
>> > and thus far I have NOT been declaring my code segments extern. Is this
>> ok,
>> > or will it break in future OSs? What is extern really doing in the
>> sample
>> > code? It seems unnecessary for a single segment program.
>>
>> the "extern" keyword is primarially being used to tell the
>> compiler that a function or variable is defined somewhere
>> else in the source code (ie, another file that may not be
>> included in the current file context).
>>
>> most of the time, if you forget to declare it extern, the
>> compiler will complain and say "what is this?" - mainly because
>> you have not defined it anywhere.
>>
>> if all your code is in one file, you wont need the
>> "extern" declarations.. but doing so (one large file) is
>> normally considered "bad practice" (hope i dont step on
>> some toes here).. seperate files enforce some form of
>> modularity.
>>
>> cheers.
>>
>> az.
>> --
>> Aaron Ardiri
>> Lecturer http://www.hig.se/~ardiri/
>> University-College i G�vle mailto:[EMAIL PROTECTED]
>> SE 801 76 G�vle SWEDEN
>> Tel: +46 26 64 87 38 Fax: +46 26 64 87 88
>> Mob: +46 70 656 1143 A/H: +46 26 10 16 11
>>
>>