Skip to content

Instantly share code, notes, and snippets.

@Houdini
Created October 11, 2015 21:00
Show Gist options
  • Save Houdini/879d8805917ea64913c9 to your computer and use it in GitHub Desktop.
Save Houdini/879d8805917ea64913c9 to your computer and use it in GitHub Desktop.
#include <sys/queue.h>
#include <stdlib.h>
#include <stdio.h>
struct entry {
SLIST_ENTRY(entry) next;
};
SLIST_HEAD(top, entry) head;
int main() {
SLIST_INIT(&head);
struct entry *n1 = malloc(sizeof(struct entry));
SLIST_INSERT_HEAD(&head, n1, next);
struct entry *n2 = malloc(sizeof(struct entry));
SLIST_INSERT_HEAD(&head, n2, next);
struct entry *np;
SLIST_FOREACH(np, &head, next) {
printf("Helo\n");
free(np);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment