Help needed with #include problems

Peter da Silva peter at ficc.UUCP
Fri Jun 3 01:34:30 AEST 1988


In article <7948 at brl-smoke.ARPA>, gwyn at brl-smoke.ARPA (Doug Gwyn ) writes:
> In article <998 at mit-caf.UUCP> vlcek at mit-caf.UUCP (Jim Vlcek) writes:
> >Putting initialization data for a global variable into an
> >#include file seems to me almost an act of violence!
> 
> I don't know about violent, but it's a sure sign of source code out of
> control.

I disagree. It's a good idea to stick your declarations and initialisation
in one place. When you change a variable, or add one, or delete one, you
really need to make sure you get all the declarations. It's much more
convenient if it's all in one place.

But, do it intelligently:

---- foo.h
#ifdef FOO_C
#define GLOBAL
#define INIT(x) =x
#else
#define GLOBAL extern
#define INIT(x)
#endif

GLOBAL char *fooname INIT("foo");
GLOBAL char *footype INIT("program");

#undef GLOBAL
#undef INIT
----

And then:

---- foo.c
#define FOO_C

#include "this.h"
#include "that.h"
#include "foo.h"
#include "the_other.h"
-- 
-- Peter da Silva, Ferranti International Controls Corporation.
-- Phone: 713-274-5180. Remote UUCP: uunet!nuchat!sugar!peter.



More information about the Comp.lang.c mailing list