delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/05/09/05:51:28

Newsgroups: comp.os.msdos.djgpp
Date: Fri, 9 May 1997 11:43:21 +0200 (MET DST)
From: Wojciech Piechowski <voyt AT delta DOT ds2 DOT pg DOT gda DOT pl>
To: rellwood <rellwood AT aludra DOT usc DOT edu>
cc: djgpp AT delorie DOT com
Subject: Re: Global Variables
In-Reply-To: <Pine.SV4.3.94.970508164914.13011B-100000@aludra.usc.edu>
Message-ID: <Pine.GSO.3.96.970509113814.1106A-100000@delta.ds2.pg.gda.pl>
References: <Pine DOT SV4 DOT 3 DOT 94 DOT 970508164914 DOT 13011B-100000 AT aludra DOT usc DOT edu>
MIME-Version: 1.0


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
> 
> 
> 
> -- 
> 
> 

You should declare these variables in only one module (you can even create
a module with all the global variables and nothing else). Then create an
include file where these variables are with 'extern' modifier. Something
like this:

/* globals.c */

int global_variable;
...



/* globals.h */

extern int global_variable;




You sgould #include globals.h in every module which
uses any of these variables.


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019