Glib: foreach with (GFunc) printf running failed

pprun pprun.dragon at gmail.com
Sun Sep 2 02:30:33 UTC 2012


Hi, all,
I'm just back to c, and using Glib data type now.
However, I found almost all g_xxx_foreach call failed while working with 
printf GFunc, see below code snip.
Replaced printf with puts, it worked.

If this topic was discussed before, could you please point me the link? 
Or, give me some hints.

Thanks.


---------- code sample -----------
int main(int argc, char** argv)
{
	GQueue* q = g_queue_new();
	
	g_queue_push_tail(q, "Alice ");
	g_queue_push_tail(q, "Bob ");
	g_queue_push_tail(q, "Fred ");
	
	printf("Starting out, the queue is: ");
	g_queue_foreach(q, (GFunc) printf, NULL); // failed here
	
	g_queue_reverse(q);
	printf("\nAfter reversal, it's: ");
	g_queue_foreach(q, (GFunc) printf, NULL); // failed here
	
	GQueue* new_q = g_queue_copy(q);
	g_queue_reverse(new_q);
	printf("\nNewly copied and re-reversed queue is: ");
	g_queue_foreach(new_q, (GFunc) printf, NULL); // failed here
	
	g_queue_free(q);
	g_queue_free(new_q);
	return 0;
}




More information about the pkg-gnome-maintainers mailing list