effect of free()

ody davidsen at sungod.crd.ge.com
Sat Aug 19 07:39:55 AEST 1989


In article <1989Aug17.005548.745 at twwells.com> bill at twwells.com (T. William Wells) writes:
| 
| 	char    *ptr;
| 
| 	ptr = malloc(1);
| 	...
| 	free(ptr);
| 	...
| 	if (ptr == 0) ...
| 
| The if might cause a trap when the value of ptr is accessed.

  As far as I can see you have to be able to test the value of a pointer
to see if it's valid in any implementation, and as long as you don't
dereference the pointer I don't see any portability problems.

  The test to see if ptr is zero (ie. NULL) would be better placed after
the malloc, before trying the free...
	bill davidsen		(davidsen at crdos1.crd.GE.COM)
  {uunet | philabs}!crdgw1!crdos1!davidsen
"Stupidity, like virtue, is its own reward" -me



More information about the Comp.lang.c mailing list