[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: Structs
- From: Michael Rothwell <rothwell holly-springs nc us>
- To: "Josh 'Gage'" <antgage apk net>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: Structs
- Date: Mon, 30 Oct 2000 21:20:08 -0500
Several problems that I see;
You're attempting to use a keyword as a variable name here:
> struct_t *struct;
try this instead:
struct_t *my_widget_struct;
Here, you haven't malloced any memory for your struct:
> struct_t->widget1 = gtk_widget_new("useless widget 1");
> struct_t->widget2 = gtk_widget_new("useless widget 2");
If you had said:
struct_t my_widget_struct; // notice, no "*"
Then you could do this:
my_widget_struct.widget1 = gtk_widget_new("useless widget 1");
my_widget_struct.widget2 = gtk_widget_new("useless widget 2");
If you want to keep using a pointer to your struct, do this:
struct_t *my_widget_struct;
my_widget_struct=(struct_t *)malloc(sizeof(struct_t));
my_widget_struct->widget1 = gtk_widget_new("useless widget 1");
my_widget_struct->widget2 = gtk_widget_new("useless widget 2");
-M
> Josh 'Gage' wrote:
>
> 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 :(
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]