Re: [gtk-list] Re: gtk break the code into files programming question (fwd)




On Tue, 2 Jun 1998, Travis Loyd wrote:
> 
> Assume I have created the menu_bar correctly cause putting this all in a
> file works correctly... trying to pass it back is where the problem comes
> in, this is the error I recieve:
> 
> 	gcc -c gscreen.c
> 	gscreen.c: In function `display_screen':
> 	gscreen.c:18: warning: assignment from incompatible pointer type
>

This is because you have a GtkWidget * and you cast to GtkMenuBar * - just
don't cast it.
 
> So if I change menu_bar to be of type GtkMenuBar the error becomes:
> 
> 	gscreen.c: In function `display_screen':
> 	gscreen.c:19: warning: passing arg 2 of `gtk_container_add' from 
> 	incompatible pointer type
> 

You need to cast like GTK_WIDGET(menu_bar)

> So if I change menu_bar to be of type GtkMenuBar* and cast arg2 of
> container_add to (GtkWidget*) I get a flawless compile and a core dump. It

You should use GTK_WIDGET() instead of (GtkWidget *) and you will get
better error messages at runtime.


If you are doing this (in effect):

GtkWidget * menu_bar;
GtkWidget * container;

container = gtk_whatever_new();
menu_bar = gtk_menu_bar_new();
gtk_container_add(GTK_CONTAINER(container), menu_bar);

It ought to work. There is no reason being in separate files should make
any difference. You must be doing something else wrong - freeing the
memory, corrupting it otherwise, passing the wrong pointer, ???

Have you verified the cause of the core dump with gdb?

Havoc Pennington ==== http://pobox.com/~hp






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