Created
July 1, 2010 21:19
-
-
Save danlei/460583 to your computer and use it in GitHub Desktop.
gslist.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <glib.h> | |
// gcc -o gslist gslist.c `pkg-config --cflags --libs glib-2.0` | |
typedef struct { | |
char *name; | |
int size; | |
} Person; | |
int main(int argc, char **argv) { | |
GSList *list = NULL; | |
Person *dan = malloc(sizeof *dan); | |
dan->name = "Daniel"; | |
dan->size = 179; | |
list = g_slist_append(list, dan); | |
Person *fred = g_new(Person, 1); | |
fred->name = "Fred"; | |
fred->size = 200; | |
list = g_slist_append(list, fred); | |
printf("dan's size is %i\n", ((Person *)list->data)->size); | |
printf("last person's name is %s\n", ((Person *)g_slist_last(list)->data)->name); | |
g_slist_free(list); | |
free(dan); | |
g_free(fred); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment