question about free()
John Vanderpool
vander at nssdcb.gsfc.nasa.gov
Wed Aug 1 07:40:29 AEST 1990
does the free() function return anything?
in VAXC v3.0 it's defined as: void free (void *ptr);
i though it used to (just to tell you it was successful)
- was that an incorrect implementation ?
if the argument is void *ptr how does it know how many bytes to release?
which brings me to my example (attached) do i need to cast the pointer
before free()ing it?
thanx, hope this isn't too stupid!
fish
------------------------------------------------------------------------------
/* each type of XAB is a different size structure on VAX/VMS for unix folks */
#include xab
#define NULL (void *) 0
void RMS_free_XABchain( struct XABKEY *xabp )
/* originally had as void *xabp but then you can't reference its
elements */
{
/* cast XAB pointer using XAB type code in xab$b_cod */
switch( xabp->xab$b_cod )
{
case XAB$C_ALL : xabp = (struct XABALL *) xabp; break;
case XAB$C_DAT : xabp = (struct XABDAT *) xabp; break;
case XAB$C_FHC : xabp = (struct XABFHC *) xabp; break;
case XAB$C_KEY : xabp = (struct XABKEY *) xabp; break;
case XAB$C_PRO : xabp = (struct XABPRO *) xabp; break;
case XAB$C_RDT : xabp = (struct XABRDT *) xabp; break;
case XAB$C_SUM : xabp = (struct XABSUM *) xabp; break;
case XAB$C_TRM : xabp = (struct XABTRM *) xabp; break;
default : printf( "bad xab code=%d\n", xabp->xab$b_cod ); return;
} /* end switch */
/* recursively call until end of chain is reached, free on unwind */
if( xabp != NULL )
{
RMS_free_XABchain( xabp->xab$l_nxt );
free( xabp );
}
} /* RMS_free_XAB_chain */
More information about the Comp.lang.c
mailing list