* extern storage class & multiple declaration
@ 2002-08-22 7:52 Alina Valea
2002-08-22 8:02 ` Jan-Benedict Glaw
0 siblings, 1 reply; 2+ messages in thread
From: Alina Valea @ 2002-08-22 7:52 UTC (permalink / raw)
To: linux-c-programming
Hello everybody,
Suppose we have:
---------------------------------------- file.h
extern int i; ----------------------------------------
and ---------------------------------------- file.c
#include "file.h"
int i; ...
/* No actual use of i here */
------------------------------------------
----------------------------------------- another_file.c
#include "file.h"
void func() {
i=3; }
-----------------------------------------
I know this is entirely correct, but is it an acceptable
programming habit?
Thank you, Alina
----
Home, no matter how far...
http://www.home.ro
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: extern storage class & multiple declaration
2002-08-22 7:52 extern storage class & multiple declaration Alina Valea
@ 2002-08-22 8:02 ` Jan-Benedict Glaw
0 siblings, 0 replies; 2+ messages in thread
From: Jan-Benedict Glaw @ 2002-08-22 8:02 UTC (permalink / raw)
To: linux-c-programming
[-- Attachment #1: Type: text/plain, Size: 1371 bytes --]
On Thu, 2002-08-22 07:52:34 -0000, Alina Valea <avalea@home.ro>
wrote in message <20020822075234.20104.qmail@relay1.home.ro>:
> Hello everybody,
>
> Suppose we have:
[
file.h declares a variable,
file.c defines it, but doesn't use it and
some_file.c includes file.h and uses mentioned variable
]
> I know this is entirely correct, but is it an acceptable
> programming habit?
This is not only correct but also done very often. Sometimes, you can't
go around global variables. In such a case, it's better to have a
"globals.h" (declaring *all* global variables) and a matchins globals.c
file (defining them all, possibly initializing them to useful default
values).
This is a _lot_ better than spreading all those global variables over a
zillion .c files, and locally declaring them in any .c file which uses
(but doesn't define) it. That's quite error-prone (eg. small things like
signed <-> unsigned conflicts *will* come up at some time, and you'll
spend a day or two for searching the difference).
Having all global variables (if any exist) iat one place (in conjunction
with a matching header file) is a good thing helping to not do stupid
mistakes...
MfG, JBG
--
Jan-Benedict Glaw . jbglaw@lug-owl.de . +49-172-7608481
-- New APT-Proxy written in shell script --
http://lug-owl.de/~jbglaw/software/ap2/
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-08-22 8:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-08-22 7:52 extern storage class & multiple declaration Alina Valea
2002-08-22 8:02 ` Jan-Benedict Glaw
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).