Re: C/GTK question



What you need to do is this:

One file that uses the mainwindow variable, the one that initializes it,
usually, needs the actual variable.  So:

gtk_main.c (or whatever):
  GtkWidget *mainwindow;

  int main() {
    ...
  }

gtk_secondary.c (or whatever):
  extern GtkWidget *mainwindow;

  int doSomething() {
    ...
  }


Notice that the variable is only actually declared once.  The other files
are just informed that there is an *external* variable of that type with
that name.  That way they can use the variable without redeclaring it
(Which is against the rules).

However, I think GTK is probably not the best place to be learning C.  GTK
is rather advanced C, lots of pointers and enums and whatnot... I'd
recommend starting out a little slower, and looking at GTK once you're
more comfortable with the language.  But whatever works :)

Good luck!

- Nate

I'm building an application in C that uses GTK. The reason i'm doing this
is
to learn GTK (and C as well) the main problem I've found is that i write
all
the GTK code in only one file and is getting too da## big, so i tried to
divide the GTK code in different files, but it seems i'm do not understand
C
that good. This is what i did:

global.c
                                               GtkWidget *mainWindow

gtkarch1.c           gtkarch2.c          gtkarch3.c           gtkarch4.c
/* Al this files uses the mainWindow variable, this is what i do:
gtkarchX.c
      #include global.c
      GtkWidget *mainWindow */

ant then the main.c file which looks like this:

main.c
#include "gtkarch1.c"
#include "gtkarch2.c"
#include "gtkarch3.c"

But the compiler gives me an error, which I understand but i don't know
how
to solve it, that says that i'm redefining the variables declared in
global.c in each gtkarchX.c

So............ Help? please?
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list






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