Страницы

Translate

воскресенье, 3 ноября 2013 г.

Exercise 6.5. Write a function undef that will remove a name and definition from the table maintained by lookup and install.



Exercise 6.5. Write a function undef that will remove a name and definition from the table
maintained by lookup and install.


/* undef: remove the name and definition of the table */
void undef(char *s)
{
    int h;
    struct nlist *prev, *np;
    
    prev = NULL;
    h = hash(s);    //hash string s
    for(np = hashtab[h]; np != NULL; np = np->next)
    {
        if(strcmp(s, np->name) == 0)
            break;
        prev = np;
    }
    if(np != NULL)  // name found
    {
        if(prev == NULL)    // it is first name in hash
            hashtab[h] = np->next;
        else    //not first
            prev->next = np->next;
        free((void *) np->name);
        free((void *) np->defn);
        free((void *) np);  //releases the dedicated structure
    }
}

Комментариев нет:

Отправить комментарий