tags:

views:

83

answers:

2

I have a simple cpp file which uses GIO. I have stripped out everything to show my compile error:

Here is the error I get:

My.cpp:16: error: invalid conversion from ‘int’ to ‘GIOCondition’
make[2]: *** [My.o] Error 1

Here is the complete file:

#include <glib.h>

static gboolean
read_socket (GIOChannel *gio, GIOCondition condition, gpointer data)
{
  return false;
}


void createGIOChannel() {
  GIOChannel* gioChannel = g_io_channel_unix_new(0);
  // the following is the line causing the error:
  g_io_add_watch(gioChannel, G_IO_IN|G_IO_HUP, read_socket, NULL);
}

I have seen other example using gio, and I am doing the same thing in term of calling G_IO_IN|G_IO_HUP. And the documentation http://www.gtk.org/api/2.6/glib/glib-IO-Channels.html, said I only need to include , which I did.

Can you please tell me how to resolve my error?

One thing I can think of is I am doing this in a cpp file. But g_io_add_watch is a c function?

Thank you for any help. I have spent hours on this but did not get anywhere.

+1  A: 

You can Cast it

(GIOCondition) G_IO_IN|G_IO_HUP 

or

void createGIOChannel() {
  GIOChannel* gioChannel = g_io_channel_unix_new(0);
  // the following is the line causing the error:
  GIOCondition cond = G_IO_IN|G_IO_HUP;
  g_io_add_watch(gioChannel, cond , read_socket, NULL);
}
fabrizioM
Thanks. But why I need to cast it if GIOCondition is defined as 'enum' typedef enum{ G_IO_IN GLIB_SYSDEF_POLLIN, G_IO_OUT GLIB_SYSDEF_POLLOUT, G_IO_PRI GLIB_SYSDEF_POLLPRI, G_IO_ERR GLIB_SYSDEF_POLLERR, G_IO_HUP GLIB_SYSDEF_POLLHUP, G_IO_NVAL GLIB_SYSDEF_POLLNVAL} GIOCondition;
michael
GIOCondition is the user defined type, so you should typecast to it. For more information on enums refer http://cplus.about.com/od/introductiontoprogramming/p/enumeration.htm
Jay
A: 

I guess it is flagging an error as you must be using a CPP Compiler which does strict typechecking.

Incase of a C compiler, that should mostly be a warning.

You can typecast it ((GIOCondition) G_IO_IN|G_IO_HUP) or create a variable of type GIOCondition and pass the same to the function.

Jay