The C programming language 2nd edition page129

error?

struct nlist *install(char *name, char *defn)
{
......
if ((np = lookup(name)) == NULL) { /* not found */
np = (struct nlist *) malloc(sizeof(*np));
if (np == NULL || (np->name = strdup(name)) == NULL) return NULL;
hashval = hash(name);
np->next = hashtab[hashval];

/* here, I think it is supposed to be looking up the last np
by iterating over the *hashtab[hashval], where the last_np->next == NULL,
coded like
for (np=hashtab[hash(s)];;np=np->next)
if (np->next == NULL) {lastnp=np;break;}
and then update the last_np->next with the newly malloced np,
while the new np->next=NULL since it is the last of the linked list. */

hashtab[hashval] = np;
} else /* already there */
free((void *) np->defn); /*free previous defn */

if ((np->defn = strdup(defn)) == NULL)
return NULL;
return np;
}
¿Que?
Topic archived. No new replies allowed.