delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/05/09/15:34:48

From: Erik Max Francis <max AT alcyone DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Global Variables
Date: Fri, 09 May 1997 09:46:24 -0700
Organization: Alcyone Systems
Lines: 27
Message-ID: <337354E0.2895110@alcyone.com>
References: <Pine DOT SV4 DOT 3 DOT 94 DOT 970508164914 DOT 13011B-100000 AT aludra DOT usc DOT edu>
NNTP-Posting-Host: newton.alcyone.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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.

You need to define them as extern in the header, not declare them there.

In the module (say):

    int x;

and in the header:

    extern int x;

-- 
       Erik Max Francis, &tSftDotIotE / email / max AT alcyone DOT com
                     Alcyone Systems /   web / http://www.alcyone.com/max/
San Jose, California, United States /  icbm / 37 20 07 N  121 53 38 W
                                   \
                      "The future / is right there."
                                 / Bill Moyers

- Raw text -


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