Re: Global GList in gtk+ application
- From: Colomban Wendling <lists ban herbesfolles org>
- To: gtk-app-devel-list gnome org
- Subject: Re: Global GList in gtk+ application
- Date: Sat, 12 Jun 2010 14:12:41 +0200
Le 12/06/2010 08:03, Alexander Kuleshov a écrit :
[snip]
I have a function bulid my list:
gboolean build_list()
{
Data->list = g_list_append(Data->list, "First ");
Data->list = g_list_append(Data->list, "Second ");
Data->list = g_list_append(Data->list, "Third ");
g_list_foreach(Data->list, (GFunc)printf, NULL);
}
Using printf() as a void (*func)(void*, void*) is pretty unsafe: apart
the inexact signature[1], imagine one of your strings contains something
like a "%something" understood by printf(), what's gonna happen? Bad things.
Prefer using something like puts() or a personal function that follows
the needed semantic.
After calling this function to display all items from the list:
First Second Third
,but when i try to make it in another function - for example:
void foreach()
{
g_list_foreach(Data->list, (GFunc)printf, NULL);
}
I see error in gdb: SEGFAULT
*Program received signal SIGSEGV, Segmentation fault. [Switching to
Thread 0xb7335700 (LWP 5364)] 0xb765a7d7 in strchrnul () from
/lib/i686/cmov/libc.so.6 *
How can i create global list in my application?
Global lists are probably not the problem, unless you use threads and
tries to access the list both in read an write without locks -- an even
there the problem wouldn't be the lists though.
And there's far from enough information to help you, even if as Tor said
it has more than probably little to do with GTK.
Regards,
Colomban
[1] AFAIK it doesn't matters much, at least on x86-style platforms --
but don't trust me on this.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]