mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: William Lee Irwin III <wli@holomorphy.com>
To: Daniel Phillips <phillips@arcor.de>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Generic list push/pop
Date: Mon, 19 Aug 2002 05:05:50 -0700	[thread overview]
Message-ID: <20020819120550.GA21683@holomorphy.com> (raw)
In-Reply-To: <E17gVcL-00031m-00@starship>

On Sun, Aug 18, 2002 at 09:21:41PM +0200, Daniel Phillips wrote:
> I took a run at writing generic single-linked list push and pop macros, to be 
> used in the form:

Dear gawd, I've gone blind.

How's this look?


Cheers,
Bill


struct slist
{
	struct slist *next;
};


static inline void slist_add(struct slist *head, struct slist *elem)
{
	elem->next = head->next;
	head->next = elem;
}

#define slist_push(head, elem)	slist_add(head, elem)

static inline struct slist *slist_pop(struct slist *head)
{
	struct slist *elem = head->next;

	if (elem) {
		head->next = elem->next;
		elem->next = NULL;
	}
	return elem;
}

static inline int slist_remove(struct slist *head, struct slist *elem)
{
	struct slist *curr, *prev;

	for (prev = head, curr = head->next; curr; prev = curr, curr = curr->next)
		if (curr == head) {
			prev->next = curr->next;
			curr->next = NULL;
			return 1;
		}

	return 0;
}

  parent reply	other threads:[~2002-08-19 12:02 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-18 19:21 Daniel Phillips
2002-08-18 19:28 ` Thunder from the hill
2002-08-18 20:34   ` Daniel Phillips
2002-08-19 12:05 ` William Lee Irwin III [this message]
2002-08-19 12:32   ` Daniel Phillips
2002-08-20 13:08   ` Thunder from the hill
2002-08-20 15:30     ` Daniel Phillips
2002-08-20 15:45       ` Thunder from the hill

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020819120550.GA21683@holomorphy.com \
    --to=wli@holomorphy.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=phillips@arcor.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®