Comment

Comment by nemetroid

I'm not sure why the article removed comments from the code and replaced variable names like "indirect" with "p". Here are the two code samples verbatim from Linus's presentation:

  remove_list_entry(entry)
  {
      prev = NULL;
      walk = head;
  
      // Walk the list
  
      while (walk != entry) {
          prev = walk;
          walk = walk->next;
      }
  
      // Remove the entry by updating the
      // head or the previous entry
  
      if (!prev)
          head = entry->next;
      else
          prev->next = entry->next;
  }
  
  remove_list_entry(entry)
  {
      // The "indirect" pointer points to the
      // *address* of the thing we'll update
  
      indirect = &head;
  
      // Walk the list, looking for the thing that
      // points to the entry we want to remove
  
      while ((*indirect) != entry)
          indirect = &(*indirect)->next;
  
      // .. and just remove it
      *indirect = entry->next;
  }
parent nemetroid 5 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton