malloced structure initilization

Henry Spencer henry at utzoo.uucp
Fri Feb 10 13:48:19 AEST 1989


In article <202 at sabin.UUCP> bjm at 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?

You can try using bcopy() or memset() (Berklix and SysV respectively), but
beware that things like pointers and floating-point numbers are *not*
guaranteed to be initialized to anything sensible that way.  The only way
to reliably initialize such things to specific values (like, say, NULL
or 0.0) is to do member-by-member initialization.  The bit patterns for
NULL and 0.0 are not guaranteed to be all zeros.
-- 
The Earth is our mother;       |     Henry Spencer at U of Toronto Zoology
our nine months are up.        | uunet!attcan!utzoo!henry henry at zoo.toronto.edu



More information about the Comp.lang.c mailing list