Block Initialization

Tom Stockfisch tps at sdchem.UUCP
Fri Oct 24 06:35:46 AEST 1986

In article <3965 at umcp-cs.UUCP> chris at umcp-cs.UUCP (Chris Torek) writes:
>>>The chore is to initialize the entire structure to zero.  How do I do it?
>Structure assignment is fine in most cases, but suppose instead that
>some hapless programmer is supposed to initialise a 40K-byte structure
>using a small model compiler on an IBM PC?  There is no space for a
>second copy of the structure.  Using bzero() here (assuming it exists,
>or after writing it) is reasonable, given the compiler limitations.

The obvious solution is to make assignment of zero to any structure a
defined operation guaranteed to get the appropriate bit patterns into
all the pointer elements.  Much cleaner than

	struct big_sucker { ... }	zero;	/* initialized to all zeros */
		struct big_sucker	var;
		var =	zero;	/* clear all elements of var */

would be
		var =	0;	/* (no comment needed) */

and much better for portability than using bzero().
I hope this gets provided for in ANSI C.

-- Tom Stockfisch, UCSD Chemistry

More information about the Comp.lang.c mailing list