Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ames!pasteur!ucbvax!ucsd!ucsdhub!esosun!seismo!uunet!vsi!friedl
From: friedl@vsi.UUCP (Stephen J. Friedl)
Newsgroups: comp.lang.c
Subject: Re: Variable dimensioning in fortran (now in C)
Summary: a true allocator
Message-ID: <734@vsi.UUCP>
Date: 27 Jun 88 06:53:05 GMT
References: <2742@utastro.UUCP> <20008@beta.UUCP> <224@raunvis.UUCP> <8168@brl-smoke.ARPA>
Organization: V-Systems, Inc. -- Santa Ana, CA
Lines: 39

In article <8168@brl-smoke.ARPA>, gwyn@brl-smoke.ARPA (Doug Gwyn ) writes:
> >What makes you think calloc() is VAX-specific?
> 
> It's true that calloc() exists universally, but its function is to allocate
> memory and initialize it with 0 BYTE data.  That does not in general
> properly initialize all data types (particularly floating-point and
> pointer types), thus the necessity of malloc() followed by an explicit
> initialization loop.  On a VAX this use of calloc() typically happens to
> work, by accident.

This has been my approach to a Q&D allocator for some
kind of arbitrary data type:

/*
 * objalloc()
 *
 *	Return one initialized item.
 */

typedef struct object	OBJ;

OBJ *
objalloc()
{
static OBJ dummy;	/* guaranteed to be "the right" zeros	*/
OBJ	   *p;

	p = (OBJ *)Malloc(sizeof(*p));	/* does error checking internally */

	*p = dummy;			/* do a *real* initialization	  */

	return(p);
}


-- 
Steve Friedl     V-Systems, Inc. (714) 545-6442     3B2-kind-of-guy
friedl@vsi.com     {backbones}!vsi.com!friedl    attmail!vsi!friedl

Nancy Reagan on the Free Software Foundation : "Just say GNU"