[comp.lang.c] initializing variables

braner@batcomputer.tn.cornell.edu (braner) (12/23/86)

[]

In article <1888@batcomputer.tn.cornell.edu> I wrote:
>>As for compile vs. run time initialization of arrays:  A compiler I
>>use creates code for all the initializations in the program ...
>>Even worse, when an array is initialized, this compiler generates a line
>>of code to initialize each entry, rather than an image of the array and
>>looping code.

To which Greg Smith replied:
>Hopefully the link environment is such that this code is
>all bunched together.
- It is.

>If I say:
>foo(){
>	static int bar=0;
>	...
>then 'bar' must be set to zero sometime before the first call to 'foo', and
>must *not* be set to zero on subsequent calls to foo. On braner's compiler,
>does this work,
- it sure does.

> and if so, how? Does the compiler put 'CLR bar' into a
>separate code area which is executed at startup? This sounds like more
>trouble than real initialization...
- yes, it does exactly that, although I don't see why it is "more trouble".
The real problem is with BIG, INITIALIZED arrays.  Perhaps they assumed that
those are not common enough to worry about (most programs with large amounts
of pre-written data read it from a separate file.  Or do they? - personally
I like to have everything in one file.)

- Moshe Braner