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

Re: Structs



> Hey guys.
> 
> I'm trying to organize all my pertinent data widgets into a nice structure so that when I have to pass them around to functions it's easy on me(the programmer). I'm having a few problems tho...
> 
> /***** Example Code */
> typedef struct
> {
>     GtkWidget *widget1;
>     GtkWidget *widget2;
>     ...
> } struct_t;
> 
> int main( int argc, char *argv[] )
> {
>     struct_t *struct;
> 
>     struct_t->widget1 = gtk_widget_new("useless widget 1");
>     struct_t->widget2 = gtk_widget_new("useless widget 2");
> 
>     gtk_widget_show( struct_t->widget1 );
>     gtk_widget_show( struct_t->widget2 );
>     ...
>     g_print( "Quitting Program!\n" );
>     return 0;
> }
> /***** End of Example Code */
> 
> this is just a small piece of code, and as such is incomplete in the gtk+ api(no init, etc.). please ignore that :)
> 
> When i try to compile this, ill usually get an error, and if i dont error the compile, i segfault on exit. Any help on this? I would REALLY like to organize my data, but this struct makes me want to hit it like a red headed step child :(
> 
> 
> 
This may be an obvious part of your code that you didn't show, but did you allocate any
memory for the struct?
ie.
struct_t *struct;
struct = g_malloc0(sizeof(struct_t));
...
g_print("Quitting Program!\n");
g_free(struct);
return 0;





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