Xref: utzoo comp.lang.c:30687 comp.os.vms:28547 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!ncar!ico!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c,comp.os.vms Subject: Re: question about free() Message-ID: <17190@haddock.ima.isc.com> Date: 1 Aug 90 01:52:18 GMT References: <2958@dftsrv.gsfc.nasa.gov> Reply-To: karl@kelp.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Cambridge, MA 02138-5302 Lines: 39 In article <2958@dftsrv.gsfc.nasa.gov> vander@nssdcb.gsfc.nasa.gov writes: >does the free() function return anything? No. >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 ? Since free() cannot fail unless the program is already seriously broken, there's not much point. It might as well use abort() to flag the error. >if the argument is void *ptr how does it know how many bytes to release? Magic. (I mean that seriously.) It's not something the user needs to be concerned with; the implementation will remember the size somehow. >which brings me to my example (attached) do i need to cast the pointer >before free()ing it? You should be okay as long as `free()' has been declared with a prototype. (It's sufficient to #include if your compiler is ANSI-compliant.) On a compiler without prototypes, you should cast the argument to `char *' (or `void *' if you have it, but this is also an ANSI invention) for complete portability. (It looks like *this* code will never be ported off a vax anyway, but it's good programming practice, and makes lint happy.) >void RMS_free_XABchain( struct XABKEY *xabp ) >/* originally had as void *xabp but then you can't reference its elements */ If this is a pointer to a generic class of structs that all share a common initial member, you could use `void *xabp' and reference the common member with `((struct XABKEY *)xabp)->xab$b_cod'. > case XAB$C_ALL : xabp = (struct XABALL *) xabp; break; This almost certainly isn't what you want. Karl W. Z. Heuer (karl@kelp.ima.isc.com or ima!kelp!karl), The Walking Lint