Re: g_array_new problem with initializer element



On Mon, Dec 25, 2006 at 12:22:50AM -0500, Tony Freeman wrote:
What am I doing wrong?  I would like an array of gchar values.  The
gchar values would be "lx1" "lx2" "dx1" that a user would select from a
GtkTreeView.

Why you ceate some GArray instead of a GtkListStore -- you
will have to create a tree model anyway, so why not use it
directly as the storage?

However, the following line gives an error:

GArray *serverlist = g_array_new(TRUE, FALSE, sizeof(gchar));

"lx1" and "lx2" do not look like single characters, so this
is probably wrong.  You created an array of *characters*,
not an array of strings.

The error is:

main.c:58: error: initializer element is not constant

serverlist is a global variable, right?  Global variables
have to be initialized with constants in C.  You can move
the initializer to main() or some initialization function,
but global variables are Evil and in most cases the best
approach is to avoid them anyway.

Yeti


--
Whatever.



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