[comp.lang.c] .header

vlcek@mit-caf.MIT.EDU (Jim Vlcek) (07/07/88)

In article <1002@ficc.UUCP> peter@ficc.UUCP (Peter da Silva) wonders
what the heck I'm talking about:

>> If one changes/deletes a variable in an #include file, one must
>> comb through every source file using that #include file and
>> change/delete every reference to that variable.
>
>If one deletes a global variable, one must comb through every source
>file that might be using that variable anyway. If one changes a variable,
>that's still true. Whether or not that variable is declared in an include
>file (for example, _ctype in ctype.h) or not. The same is true when you
>change an element of a structure declared in an include file.
>
>I don't understand this objection at all.

What I was saying was:  People are pointing out that putting
initializations in the .header file eliminates one variable
declaration/definition.  Hence, should one make a change or delete
such a variable, there will be one less change/deletion to make.  I
pointed out that this (one) extra change/deletion would pale compared
to the task of weeding out all references to that variable elsewhere
in the source code.

I have always believed in maintaining well-stratified conceptual
levels in my source code, to whatever extent possible.  In C, macros
help to clean up top-level source code somewhat, without the overhead
that excessive function calls would introduce.  Now, I consider a
.header file to be a template for program development; this is quite a
different conceptual level from actual data, which an initialized
variable represents.

In fact, it's not really the initialization which is bad, but the
*definition* (as opposed to declaration) of the variable in the .header
file which is wrong, never mind whether you initialize it or not.  It all
comes down to the difference between a programming environment and a
program environment.  The .header file describes the programming
environment; the preamble to the source module describes the program
environment.  A place for everything, and everything in its place.
-- 
Jim Vlcek
vlcek@caf.mit.edu
!{ihnp4,harvard,seismo,rutgers}!mit-eddie!mit-caf!vlcek

peter@ficc.UUCP (Peter da Silva) (07/11/88)

In article <1076@mit-caf.MIT.EDU>, vlcek@mit-caf.MIT.EDU (Jim Vlcek) writes:
> What I was saying was:  People are pointing out that putting
> initializations in the .header file eliminates one variable
> declaration/definition.

I have one question:

What does your compiler do when you say this?

	extern int foo;
	...
	int foo = 10;

Mine tells me I'm trying to initialise an extern and refuses to compile it.

This means, that I have two choices: either define that sucker in the
header using the technique I laid out, or don't include the .h file when
I define the variable. The latter alternative give me a place to screw up
that otherwise wouldn't exist (every other use of the variable is
accompanied by the include file).

What do you do about this?
-- 
-- `-_-' Peter (have you hugged your wolf today) da Silva.
--   U   Ferranti International Controls Corporation.
-- Phone: 713-274-5180. CI$: 70216,1076. ICBM: 29 37 N / 95 36 W.
-- UUCP: {uunet,academ!uhnix1,bellcore!tness1}!sugar!ficc!peter.

karl@haddock.ISC.COM (Karl Heuer) (07/13/88)

In article <1049@ficc.UUCP> peter@ficc.UUCP (Peter da Silva) writes:
>What does your compiler do when you say this?
>	extern int foo;
>	int foo = 10;
>
>Mine tells me I'm trying to initialise an extern and refuses to compile it.
>What do you do about this?

I'd report the bug to the vendor, and/or buy a working compiler from someone
else.

Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint