Message-Id: <199705091807.UAA03813@zeus.hu.bonus.com> From: "Abonyi Gyorgy" To: Subject: Re: Global Variables Date: Fri, 9 May 1997 20:07:44 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Precedence: bulk Andrew wrote: > In your header file, on top put something like this: > #ifndef _MY_HEADER_FILE > #define _MY_HEADER_FILE > ... > your header stuff > ... > #endif /* at the end of header file */ > > that should solve your problem. > > > On 8 May 1997, rellwood wrote: > > > How in the world do I get global variables to be global in several files > > that have been linked together? As my code is now, I have the > > declarations of the variables in a header file, but when I try to include > > it in more then one .c file the linker complians of multiple > > declairations. This, of course, makes perfect sense, so I tried making > > them each extern in the header file, but that didn't work either. > > > > What am I suppose to do here? > > > > Muchos thanks, > > Richard Ellwood > > This will not solve the problem, 'cos the different modules will process the include file either with the #ifdef... and without it.... Never define a variable in a header file !!!!! Header files (or anything included with the #include directive) are just "included", the compiler actualy doesn't know, that they are included so they will processed in every module.... To define global variables place the varibale definition in a (and just in one) module, and put an extern definition in da header file, for example: globvars.c: int dummy; globvars.h: extern int dummy; Gyorgy Abonyi Jr. loop AT hu DOT bonus DOT com http://www.hu.bonus.com/~loop