effect of free()

Dick Dunn rcd at ico.ISC.COM
Tue Aug 22 09:22:57 AEST 1989


In the midst of the pointer-to-freed-area stuff, idall at augean.OZ (Ian
Dall) writes:
> -	if (ptr == 0) ...
. . .
> Well you should strictly do something like 
> 
>       if (ptr == (char *) 0) ...

Will this *never* die?  How many times does it need to be said that you
don't have to cast 0 to compare it with a pointer?  (mutter, grumble...)

In the context of free(ptr) before the test...
> If that causes a trap your compiler and/or operating system is
> definitely broken...

No, NOT broken according to the standard.  If it causes a trap, you have
quite an unusual system (and I'd like to know what it is), but it's not
broken.  free(ptr) won't change the pointer, of course, but it is theo-
retically possible for it to change the validity of testing it.  (more to
follow on this...)
-- 
Dick Dunn     rcd at ico.isc.com    uucp: {ncar,nbires}!ico!rcd     (303)449-2870
   ...Are you making this up as you go along?



More information about the Comp.lang.c mailing list