Block Initialization

swang at calma.UUCP swang at calma.UUCP
Thu Oct 9 06:14:24 AEST 1986


------------------------------------------

What is the most suitable (fast and portable among versions of Unix)
way to do block initialization?

Say I have a big structure of close to 4 Kbytes.
	
	typedef  struct {
		....
		....
	    } bigstruct;

	sizeof(bigstruct) == 4 +/- 10 Kbytes 

The details of this structure is too long, complicated and tedious to
duplicate here.  Its size may not be exactly 4Kb.

The chore is to initialize the entire structure to zero.  How do I do it?

One possible way is a function zero():

	main()
	{
		bigstruct p;
		zero((char *)&p);
	}
	zero(p)	char *p;	/* NOTE THE TYPE */
	{
		register int i = sizeof(bigstruct);
		while (i--) *p++ = 0;
	}

Another being a library call bzero()

	main()
	{
		bigstruct p;
		bzero(&p, sizeof(p));
	}

Is bzero() the optimum for this purpose for all Unix machines?
Is it portable, the Vax version is written in assembly?


I appreciate e-mailing opinions to me.

UUCP: ucbvax!calma!swang

---------------------------------------------------------



More information about the Comp.lang.c mailing list