Deleting linked lists.

Dave Schaumann dave at cs.arizona.edu
Wed Mar 27 15:04:27 AEST 1991


In article <2636 at borg.cs.unc.edu> warner at weiss.cs.unc.edu (Byron Warner) writes:
>I was wondering, is it safe to unallocate a singly linked list like this:
>
>struct list *head; /* top of list */
>struct list *ptr = head;
>while (ptr){
>	free(ptr);
>	ptr = ptr->next;
>}

Who knows?  Who cares, when it's so easy to get it right?

struct list *head, *p, *q ;

for( p = head ; p != NULL ; p = q ) {
  q = p->next ; free(p)
  }

-- 
Dave Schaumann | dave at cs.arizona.edu | Short .sig's rule!



More information about the Comp.lang.c mailing list