Variable dimensioning in fortran (now in C)
Stephen J. Friedl
friedl at vsi.UUCP
Mon Jun 27 16:53:05 AEST 1988
In article <8168 at brl-smoke.ARPA>, gwyn at 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 at vsi.com {backbones}!vsi.com!friedl attmail!vsi!friedl
Nancy Reagan on the Free Software Foundation : "Just say GNU"
More information about the Comp.lang.c
mailing list