M
MN
Hi all,
I'm learning how to use some Glib-functions for simple linked list. I
wrote a small program that prepends 2 data (let's say to integers "1"
and "2") in list, display them, count total number of elements and
returns index of each element.
How to avoid these warnings?
warning: passing argument 1 of ‘g_list_nth’ from incompatible pointer
type
warning: format ‘%d’ expects type ‘int’, but argument 2 has type
‘struct GList *’
warning: passing argument 1 of ‘g_list_index’ from incompatible
pointer type
warning: passing argument 2 of ‘g_list_index’ makes pointer from
integer without a cast
My code is:
#include <stdio.h>
#include <stdlib.h>
#include <glib.h>
int main ()
{
GSList *list = NULL;
// Add data
list = g_slist_prepend (list, GINT_TO_POINTER (2));
list = g_slist_prepend (list, GINT_TO_POINTER (1));
// Print data
while (list)
{
printf("data is %d\n", GPOINTER_TO_INT (list -> data));
list = list -> next;
}
printf("\n");
// Get the element at poistion number
printf("First element is \"%d\"\n", g_list_nth(list, 0));
printf("Second element is \"%d\"\n", g_list_nth(list, 1));
printf("\n");
// Count number of elements
printf("Total number of elements is %d\n", g_slist_length (list));
printf("\n");
// Get the position of the element
printf("This should be 0: '%d'\n", g_list_index(list, 1));
printf("This should be 1: '%d'\n", g_list_index(list, 2));
return 0;
}
I'm learning how to use some Glib-functions for simple linked list. I
wrote a small program that prepends 2 data (let's say to integers "1"
and "2") in list, display them, count total number of elements and
returns index of each element.
How to avoid these warnings?
warning: passing argument 1 of ‘g_list_nth’ from incompatible pointer
type
warning: format ‘%d’ expects type ‘int’, but argument 2 has type
‘struct GList *’
warning: passing argument 1 of ‘g_list_index’ from incompatible
pointer type
warning: passing argument 2 of ‘g_list_index’ makes pointer from
integer without a cast
My code is:
#include <stdio.h>
#include <stdlib.h>
#include <glib.h>
int main ()
{
GSList *list = NULL;
// Add data
list = g_slist_prepend (list, GINT_TO_POINTER (2));
list = g_slist_prepend (list, GINT_TO_POINTER (1));
// Print data
while (list)
{
printf("data is %d\n", GPOINTER_TO_INT (list -> data));
list = list -> next;
}
printf("\n");
// Get the element at poistion number
printf("First element is \"%d\"\n", g_list_nth(list, 0));
printf("Second element is \"%d\"\n", g_list_nth(list, 1));
printf("\n");
// Count number of elements
printf("Total number of elements is %d\n", g_slist_length (list));
printf("\n");
// Get the position of the element
printf("This should be 0: '%d'\n", g_list_index(list, 1));
printf("This should be 1: '%d'\n", g_list_index(list, 2));
return 0;
}