"Re: Array Initialization - (nf)"

nather at utastro.UUCP nather at utastro.UUCP
Sun Jul 10 09:42:16 AEST 1983


I agree with davy that explicit initializations are wise, even when
"guaranteed" initializations are promised.  As an awk-ward example,
try the following short program on "awk" which pre-initializes every
variable, array or not:

	#! /bin/awk -f
	{
	a[i] = 12345
	printf "a[%d] = %d  ", a, i
	i = 0
	printf "a[%d] = %d\n", a, i
	}

Now, careful reading of the "awk" tutorial will tell you that "i" is
initialized to the null string, which is often zero, but not always.
(It is to printf in the above example, but *not* to the array locator).
So the above is a no-no, but less obvious than one might guess.

What is this doing in net.lang.c?  Well, I use "awk" a lot to test
out algorithms before casting them permanently into "C" -- it requires
far less overhead to get a simple program written -- but the practice
has its hazards.  

INITIALIZE!

				    Ed Nather
                             ...kpno!utastro!nather



More information about the Comp.lang.c mailing list