Path: utzoo!utgpu!utstat!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!cwjcc!gatech!hubcap!ncrcae!ncrlnk!uunet!sdrc!scjones From: scjones@sdrc.UUCP (Larry Jones) Newsgroups: comp.lang.c Subject: Re: malloced structure initilization Message-ID: <525@sdrc.UUCP> Date: 10 Feb 89 23:42:14 GMT References: <202@sabin.UUCP> <13480@duke.cs.duke.edu> Organization: Structural Dynamics Research Corp., Cincinnati Lines: 27 In article <202@sabin.UUCP> bjm@sabin.UUCP (Brendan J. McMahon) writes: >How do you initialize memory malloced for a structure without using calloc, >and without initilizing each structure element explicitly? Well, if your C compiler isn't an antique the easiest thing to do is have a static instance of the structure which is properly initialized and just assign it to the malloc-ed one. (If you do have an antique compiler, you could always use memcpy to do the assignment.) In article <13480@duke.cs.duke.edu>, khera@romeo.cs.duke.edu (Vick Khera) writes: > why not just use > bzero((char *)fooptr, sizeof(struct foo)) > to zero out the structure. besides, what's wrong with calloc()? have I > missed some point you were trying to make here? The reason for not using bzero or calloc is that all zero bit doth not a zero make. In particular, zeroing a pointer is not guaranteed to make it null, nor is zeroing a floating value guaranteed to make it 0.0. ---- Larry Jones UUCP: uunet!sdrc!scjones SDRC scjones@sdrc.UU.NET 2000 Eastman Dr. BIX: ltl Milford, OH 45150 AT&T: (513) 576-2070 "When all else fails, read the directions."