Skip to content

Instantly share code, notes, and snippets.

@flatcap
Last active September 17, 2018 20:54
Show Gist options
  • Save flatcap/105cd65e37d89fc434b2b632e85c3702 to your computer and use it in GitHub Desktop.
Save flatcap/105cd65e37d89fc434b2b632e85c3702 to your computer and use it in GitHub Desktop.
STAILQ objects
#include <stdio.h>
#include "mutt/queue.h"
struct Apple
{
int payload;
};
struct AppleNode
{
struct Apple *a;
STAILQ_ENTRY(AppleNode) entries;
};
STAILQ_HEAD(AppleList, AppleNode);
struct AppleList GlobalApples = STAILQ_HEAD_INITIALIZER(GlobalApples);
void apple_function(struct Apple *a)
{
printf("%d\n", a->payload);
}
void applelist_function(struct AppleList *al)
{
struct AppleNode *np = NULL;
STAILQ_FOREACH(np, al, entries)
{
apple_function(np->a);
}
}
int main()
{
applelist_function(&GlobalApples);
return 0;
}
#include <stdio.h>
#include "mutt/queue.h"
struct Banana
{
int payload;
STAILQ_ENTRY(Banana) entries;
};
STAILQ_HEAD(BananaList, Banana);
struct BananaList GlobalBananas = STAILQ_HEAD_INITIALIZER(GlobalBananas);
void banana_function(struct Banana *b)
{
printf("%d\n", b->payload);
}
void bananalist_function(struct BananaList *bl)
{
struct Banana *b = NULL;
STAILQ_FOREACH(b, bl, entries)
{
banana_function(b);
}
}
int main()
{
bananalist_function(&GlobalBananas);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment