🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.c
Article #9533

Block Initialization

#9533
From: swang
Date: Wed, 08 Oct 1986 20:14
50 lines
1554 bytes
------------------------------------------

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

---------------------------------------------------------
Technical Details
Message-ID: <586@calma.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!decvax!decwrl!sun!calma!swang

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!decvax!decwrl!sun!calma!swang
From: swang@calma.UUCP
Newsgroups: net.lang.c
Subject: Block Initialization
Message-ID: <586@calma.UUCP>
Date: Wed, 8-Oct-86 16:14:24 EDT
Article-I.D.: calma.586
Posted: Wed Oct  8 16:14:24 1986
Date-Received: Fri, 10-Oct-86 07:40:44 EDT
Reply-To: swang@calma.UUCP (Sin-Yaw Wang)
Distribution: na
Organization: GE/Calma Co., R&D Systems Engineering, Milpitas, CA
Lines: 50