Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!eecae!netnews.upenn.edu!rutgers!att!ulysses!andante!alice!ark From: ark@alice.UUCP (Andrew Koenig) Newsgroups: comp.lang.c Subject: Re: malloced structure initilization Message-ID: <8894@alice.UUCP> Date: 10 Feb 89 05:44:51 GMT References: <202@sabin.UUCP> Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 27 In article <202@sabin.UUCP>, bjm@sabin.UUCP (Brendan J. McMahon) writes: > Simple problem - > How do you initialize memory malloced for a structure without using calloc, > and without initilizing each structure element explicitly? > Example -- > #include > struct foo{ > int a; > long b; > char c[80]; > double d; > }; How about this? static struct foo init_foo; struct foo *fp; fp = (struct foo *) malloc (sizeof (struct foo)); *fp = init_foo; init_foo is guaranteed to be initialized because it's static. -- --Andrew Koenig ark@europa.att.com