0

I am using the 'g_timeout_add_seconds' in my code. But when i compile the following error is shown

warning: passing argument 2 of 'g_timeout_add_seconds'

g_timeout_add_seconds(1, message_cb, data); //usage

gboolean message_cb(List *data) //prototype

Community
  • 1
  • 1

1 Answers1

1

Don't get rid of the warning - fix it.

The second parameter of g_timeout_add_seconds is a function pointer (GSourceFunc) as follows:

gboolean (*GSourceFunc) (gpointer user_data);

and gpointer is a pointer to void It's not keen on you using List* data instead.

Stick to the prototype and if you are passing a List* then cast it within the callback.

Component 10
  • 10,247
  • 7
  • 47
  • 64
  • ^^ the return type is gboolean and the parameter is a pointer. what is wrong in my callback prototype?.. what is GSourceFunc. Can you give me some example – user1410356 May 23 '12 at 04:13
  • @user1410356: You are passing a `List*` not a `void*`. You need to change your callback function so that it takes a `void*` instead and then in the callback function cast from `void*` to `List*` using `reinterpret_cast`. For details on `GSourceFunc` look at (http://developer.gnome.org/glib/2.30/glib-The-Main-Event-Loop.html#g-timeout-add-seconds) and for use of `reinterpret_cast` there's some excellent answers here (http://stackoverflow.com/questions/573294/when-to-use-reinterpret-cast) – Component 10 May 23 '12 at 07:02