Deleting linked lists.
Byron Warner
warner at tsc.cs.unc.edu
Thu Mar 28 02:48:15 AEST 1991
Thanks to all of you who responded, to my post.
To summarize:
In general it is not safe to assume anything about the
contents of freed data. Most people suggested using a
temporary variable, ie:
struct list *next;
while (ptr) { next = ptr->next; free(ptr); ptr = next; }
but also some one suggested recursion:
void listfree(List *l) {
if (l->next != NULL)
listfree(l->next);
free(l->data);
free(l);
}
--
----
Byron F. Warner warner at cs.unc.edu
University of North Carolina - Chapel Hill Computer Sci Department
"The opinions expressed here should be yours."
More information about the Comp.lang.c
mailing list