home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!europa.eng.gtefsd.com!gatech!swrinde!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!ira.uka.de!math.fu-berlin.de!news.netmbx.de!Germany.EU.net!mcsun!news.funet.fi!hydra!klaava!wirzeniu
- From: wirzeniu@klaava.Helsinki.FI (Lars Wirzenius)
- Subject: Re: initialized extern variables, coded in 1 file, used in many
- Message-ID: <1993Jan28.175755.7941@klaava.Helsinki.FI>
- Organization: University of Helsinki
- References: <1993Jan26.015543.23671@netcom.com> <926@ulogic.UUCP>
- Date: Thu, 28 Jan 1993 17:57:55 GMT
- Lines: 52
-
- hartman@ulogic.UUCP (Richard M. Hartman) writes:
-
- [ define EXTERN as extern by default, as nothing in main.c ]
-
- > EXTERN int uninitialized;
- >
- > #ifdef EXTERN
- > extern int initialized1;
- > #else
- > int initialized1 = 50;
- > #endif
-
- Wouldn't it be better to do
-
- EXTERN int uninitialized;
- extern int initialized1;
-
- #ifdef MAIN
- int initialized1 = 50;
- #endif
-
- instead, since this catches any errors that may creep in when you
- forget to change one copy of the initialized1
- declarations/definitions?
-
- Of course, one might even go further and move the initializations out
- of the header altoghether, since they do no particular good there. If
- they are in the header, and you change an initialization, make will
- recompile everything even if it isn't really needed.
-
- If you do that, you can even forget about the EXTERN macro and use
- extern throughout, although then you have to add definitions for the
- uninitialized variables as well.
-
- In case you didn't guess, this is the style I use. In summary:
-
- header.h:
-
- extern int foo;
-
- main.c (or some other suitable source file):
-
- #include "header.h"
-
- int foo;
-
- Easy, simple, fairly difficult to do mistakes, doesn't require
- preprocessor trickeries.
-
- --
- Lars.Wirzenius@helsinki.fi (finger wirzeniu@klaava.helsinki.fi)
- MS-DOS, you can't live with it, you can live without it.
-