Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!decvax!ucbvax!ucbcad!nike!rutgers!caip!brl-adm!brl-smoke!gwyn From: gwyn@brl-smoke.ARPA (Doug Gwyn ) Newsgroups: net.lang.c Subject: Re: Block Initialization Message-ID: <4510@brl-smoke.ARPA> Date: Fri, 10-Oct-86 11:26:02 EDT Article-I.D.: brl-smok.4510 Posted: Fri Oct 10 11:26:02 1986 Date-Received: Sat, 11-Oct-86 06:54:18 EDT References: <586@calma.UUCP> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Distribution: na Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 27 In article <586@calma.UUCP> swang@calma.UUCP (Sin-Yaw Wang) writes: >Say I have a big structure of close to 4 Kbytes. > > typedef struct { > .... > .... > } bigstruct; > >The chore is to initialize the entire structure to zero. How do I do it? The wrong way is to use bzero(), which fills a region with 0 bytes and which exists only on Berkeley-based systems (System V/X3J11 use memset()). There are at least two problems with this: (1) the struct padding may not be accessible on some architectures, so storing into it may cause a trap; (2) 0 bytes are not necessarily appropriate representations of the value zero for all data types, especially floating-point. Try the following: static bigstruct zero; /* required to be initialized to 0s of proper types */ ... bigstruct p; p = zero; /* struct copy is optimized by compiler */