Generic list push/pop

From: Daniel Phillips (
Date: Sun Aug 18 2002 - 14:21:41 EST

I took a run at writing generic single-linked list push and pop macros, to be
used in the form:

        push_list(foo_list, foo_node);

        foo_node = pop_list(foo_list);

They came out predictably ugly:

#define push_list(_LIST_, _NODE_) \
        _NODE_->next = _LIST_; \
        _LIST_ =_NODE_;

#define pop_list(_LIST_) ({ \
        typeof(_LIST_) _NODE_ = _LIST_; \
        _LIST_ = _LIST_->next; \
        _NODE_; })

These work but imho, they are too ugly to live. For one thing, they assume
the link field is named 'next' and I don't see a nice way around that.
Before moving them to my scraps.c file I thought I'd let other people throw
some tomatoes at them.

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

This archive was generated by hypermail 2b29 : Fri Aug 23 2002 - 22:00:15 EST