Xref: utzoo comp.lang.c:30683 comp.os.vms:28534 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!rex!ames!dftsrv!nssdcb.gsfc.nasa.gov!vander From: vander@nssdcb.gsfc.nasa.gov (John Vanderpool) Newsgroups: comp.lang.c,comp.os.vms Subject: question about free() Message-ID: <2958@dftsrv.gsfc.nasa.gov> Date: 31 Jul 90 21:40:29 GMT Sender: news@dftsrv.gsfc.nasa.gov Reply-To: vander@nssdcb.gsfc.nasa.gov Organization: NASA - Goddard Space Flight Center Lines: 55 News-Software: VAX/VMS VNEWS 1.3-4 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 */