Re: gtk function with argv




 
Hi Ruben,

I think what you are looking for is a C variadic function. Something that works like g_object_set() with a 
Null terminated list of arguments.

Using dynamic glib containers might be a better choice. It is simpler to just pass a single pointer with your 
user_data to functions which is how GTK callbacks are setup. Also, I have read that variadics have some 
troubles and don't always work well if you call the functions from another language. 

Eric


//gcc -Wall ptr_array1.c -o ptr_array1 `pkg-config --cflags --libs glib-2.0`
 
#include<glib.h>
#include<stdarg.h>

static void vChart_Init1(gchar *widget, GPtrArray *series)
  {
    g_print("Init1\n");
    gint i=0;
    gint length=series->len;
    for(i=0;i<length;i++) g_print("%s\n", (gchar*)g_ptr_array_index(series, i));
  }
static void vChart_Init2(gchar *widget,...)
  {
    g_print("Init2\n");
    gchar *temp=widget;
    if(temp!=NULL)
      {
        va_list var_args;  
        va_start(var_args, widget);
        while(temp!=NULL)
          {
            g_print("%s\n", temp);
            temp=va_arg(var_args, gchar*);
          }
        va_end(var_args);
      }
  }
int main()
  {
    gchar *widget="widget";
    gchar *string1="Series A";
    gchar *string2="Series B";
    gchar *string3="Series C";
    GPtrArray *series=g_ptr_array_new();
    g_ptr_array_add(series, string1);
    g_ptr_array_add(series, string2);
    g_ptr_array_add(series, string3);

    vChart_Init1(widget, series);
    vChart_Init2(widget, string1, string2, string3, NULL);
    vChart_Init2(widget, "Series A", "Series B", "Series C", NULL);

    g_ptr_array_unref(series);

    return 0;
  }




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]