From: Alan Bork Newsgroups: comp.os.msdos.djgpp Subject: Re: Doubly-defined variables Date: Thu, 22 Oct 1998 12:06:27 -0500 Organization: Exec-PC BBS Internet - Milwaukee, WI Lines: 50 Message-ID: <70nolp$11m@newsops.execpc.com> References: NNTP-Posting-Host: narn-1-185.mdm.mke.execpc.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: daily-bugle.newsops.execpc.com 909075961 1078 (None) 169.207.136.59 X-Complaints-To: abuse AT execpc DOT com X-Mailer: Mozilla 4.06 [en] (WinNT; U) To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Toni Rasanen wrote: > > I use a .h -file to define the variables (a really stupid vay, > but...), with #ifdefs trying to make sure they won't be defined > again. In .h, there is nothing but variables (and they aren't > defined extern). I use those variables in various .c -files, > as they are global. Then I have in all .c's that use those > variables 'vars.h' included... > > eg. > in 'main.c': #include "many_others.h" > #include "gfx.h" > #include "vars.h" > in 'gfx.c': #include #include "vars.h" > > However, when I try to compile this, compler tells me that some of > (but not all!) the variables in vars.h are previously defined in some > other .c -file... This may not be a complete answer to your problems, but this is how I handle global variable. I have one header in the global vars like this... [file global.h] #ifndef __GLOBAL_H_ #define __GLOBAL_H_ #ifndef EXTERN #define EXTERN extern #endif /* EXTERN */ EXTERN int var1; EXTERN int var2; #endif /* __GLOBAL_H_ */ then in one c file (usaully the one with main I have this) #define EXTERN #include "global.h" Some things to note. None of the global vars are pre initialized. This is a requirement for this to work. Understand what is happening here. The extern directive declares without defining. But in only one place, they must be defined as well. Hope that helps. Alan