Re: problem with compiling different C files with a global structure
Debmalya Sinha writes: > Hello, > > Though this might not be the place for this type of query, this problem I'm > giving here is a simplest scale version of a problem when I am trying to split > up a large gtk source code of mine. First... http://www.catb.org/~esr/faqs/smart-questions.html Second... Every piece of your code that wants to fondle that global needs two things. It needs to know the structure's definition and it needs to know that the global exists. Does every piece of your code have access to this information? Are you getting compilation errors or linking errors? Which you are getting and where they are comming from will tell you precisely why your build is failing. Maybe you should hack out a minimal test-case with two .c files and one common header and see if your assumptions about how this works are correct. It will be easier for you to debug the problem if you boil it down. This *is* a very basic C question you should already know the answer to before you start playing with something like gtk. If your understanding of extern et al is sketchy, I can't imagine life being happier for you once you start getting into the pointers, callbacks and signal/event handling that forms the core of gtk. For what it's worth. Jeff ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: problem with compiling different C files with a global structure
On Tue, May 11, 2010 at 3:54 AM, Leon Opit wrote: > Hi Debmalya, > > Do not use automatic initialisation in variables with the extern attribute. > > Initialise a.data by assignment in main(). > ok, I'll keep that in mind. > This is not the whole story but then your example code is not exactly what > you tried to compile! > > (calling cal() in main() ) but defining call in call.c never-the-less you > get the idea) > > eh, that was a typo ! > Leon > > On 11 May 2010 07:04, Debmalya Sinha wrote: > >> Hello, >> >> Though this might not be the place for this type of query, this problem >> I'm giving here is a simplest scale version of a problem when I am trying to >> split up a large gtk source code of mine. >> >> >> I'm trying to compile a program with 3 diff C files. >> *main.c* >> *call.c* >> *global.c* >> >> I want to declare a global structure variable and assign a value to it's >> content in *main.c* >> then I will call another function (declared at *call.c* ) to print the >> global variable. >> >> I have a structure definition in *global.c* which I have declared as >> extern in the common header file *head.h* through another header file * >> global.h* >> >> Program is not compiling. >> >> Am I missing some points here? >> >> >> -- >> Regards, >> >> Debmalya Sinha >> >> Research Scientist, >> MS(R) student, >> Computer Science and Engineering >> IIT Kharagpur >> >> >> Fedora Ambassador >> Chandannagar >> India. >> >> sunnywizard.googlepages.com >> >> >> GPG Key : 6E2BD51B >> Keyserver : http://pgp.mit.edu >> >> ___ >> gtk-list mailing list >> gtk-list@gnome.org >> http://mail.gnome.org/mailman/listinfo/gtk-list >> >> > -- Regards, Debmalya Sinha Research Scientist, MS(R) student, Computer Science and Engineering IIT Kharagpur Fedora Ambassador Chandannagar India. sunnywizard.googlepages.com GPG Key : 6E2BD51B Keyserver : http://pgp.mit.edu ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: problem with compiling different C files with a global structure
On Tue, May 11, 2010 at 3:20 AM, Robert Pearce wrote: > On Tue, 11 May 2010 03:04:56 +0600 > Debmalya Sinha wrote: > > > > > Am I missing some points here? > > > Thank you for your kind reply. > You mean apart from: > 1) This is a very VERY basic C programming issue, so this is the wrong > place > I've already mentioned that; and since there are many helpful people over here, I thought it was worth giving a knock. > 2) The compiler gives you some clues when compilation fails, and > you've not reported them > Yes, they are scope problems issues. And I'm still searching for how exactly I should do the job. > 3) If you read those clues they might help you find the problem > I'm trying to figure out just that. > 4) Taking the time to think about things is usually quicker than > waiting for an answer on a mailing list > I agree, but what one does when he has already searched for the problem well and really into-the-soup? I took a chance in a belief that someone might give me some clue about doing neatly what I wanted to do. As you people have always been a great help Sir. > > > > > > Now ask yourself how the compiler knows about "data" when compiling > call.c > ___ > gtk-list mailing list > gtk-list@gnome.org > http://mail.gnome.org/mailman/listinfo/gtk-list > -- Regards, Debmalya Sinha Research Scientist, MS(R) student, Computer Science and Engineering IIT Kharagpur Fedora Ambassador Chandannagar India. sunnywizard.googlepages.com GPG Key : 6E2BD51B Keyserver : http://pgp.mit.edu ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: problem with compiling different C files with a global structure
Hi Debmalya, Do not use automatic initialisation in variables with the extern attribute. Initialise a.data by assignment in main(). This is not the whole story but then your example code is not exactly what you tried to compile! (calling cal() in main() ) but defining call in call.c never-the-less you get the idea) Leon On 11 May 2010 07:04, Debmalya Sinha wrote: > Hello, > > Though this might not be the place for this type of query, this problem I'm > giving here is a simplest scale version of a problem when I am trying to > split up a large gtk source code of mine. > > > I'm trying to compile a program with 3 diff C files. > *main.c* > *call.c* > *global.c* > > I want to declare a global structure variable and assign a value to it's > content in *main.c* > then I will call another function (declared at *call.c* ) to print the > global variable. > > I have a structure definition in *global.c* which I have declared as > extern in the common header file *head.h* through another header file * > global.h* > > Program is not compiling. > > Am I missing some points here? > > > -- > Regards, > > Debmalya Sinha > > Research Scientist, > MS(R) student, > Computer Science and Engineering > IIT Kharagpur > > > Fedora Ambassador > Chandannagar > India. > > sunnywizard.googlepages.com > > > GPG Key : 6E2BD51B > Keyserver : http://pgp.mit.edu > > ___ > gtk-list mailing list > gtk-list@gnome.org > http://mail.gnome.org/mailman/listinfo/gtk-list > > ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
Re: problem with compiling different C files with a global structure
On Tue, 11 May 2010 03:04:56 +0600 Debmalya Sinha wrote: > > Am I missing some points here? > You mean apart from: 1) This is a very VERY basic C programming issue, so this is the wrong place 2) The compiler gives you some clues when compilation fails, and you've not reported them 3) If you read those clues they might help you find the problem 4) Taking the time to think about things is usually quicker than waiting for an answer on a mailing list Now ask yourself how the compiler knows about "data" when compiling call.c ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list
problem with compiling different C files with a global structure
Hello, Though this might not be the place for this type of query, this problem I'm giving here is a simplest scale version of a problem when I am trying to split up a large gtk source code of mine. I'm trying to compile a program with 3 diff C files. *main.c* *call.c* *global.c* I want to declare a global structure variable and assign a value to it's content in *main.c* then I will call another function (declared at *call.c* ) to print the global variable. I have a structure definition in *global.c* which I have declared as extern in the common header file *head.h* through another header file *global.h* Program is not compiling. Am I missing some points here? -- Regards, Debmalya Sinha Research Scientist, MS(R) student, Computer Science and Engineering IIT Kharagpur Fedora Ambassador Chandannagar India. sunnywizard.googlepages.com GPG Key : 6E2BD51B Keyserver : http://pgp.mit.edu #include "head.h" void call(void){ printf("\n%d", a.data); } #include "head.h" struct _s{ int data; } #include "head.h" struct _s a; a.data=10; main(){ cal(); } #include #include "global.h" void call(void); extern struct _s a; ___ gtk-list mailing list gtk-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-list