delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/10/14/01:55:23

From: Erik Max Francis <max AT alcyone DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Multi-modules
Date: Tue, 13 Oct 1998 22:45:28 -0700
Organization: Alcyone Systems
Lines: 45
Message-ID: <36243A78.4A80B126@alcyone.com>
References: <362410B8 DOT CE1 AT golden DOT net>
NNTP-Posting-Host: kamali.alcyone.com
Mime-Version: 1.0
X-Mailer: Mozilla 3.01 (X11; I; Linux 2.0.30 i586)
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Gloria wrote:

> If anyone has read vol.II of "C for Dummies", you'll probably
> understand
> my question a little easier.

I'm not familiar with this book, but I think I know what the problem is.

> However, when I tried to compile, it kept saying that it
> couldn't find those pointers. Is there a different way to indicate
> that
> the variables are somewhere else in the program other than "extern".
> Oh
> yeah, I tried removing the extern thing and I got some really weird
> error messages. SOS

The extern keyword means that "here is the declaration for this object
(so you know what the type is), but it is not defined in this module." 
The difference between declaration and definition is important --
declaration simply indicates what type an object is, whereas definition
actually indicates where the object is created, if it is initialized to
anything, etc.  Throughout your program, each object can be declared
(identically, hopefully, or you will have other problems) as many times
as you like, but it must only be _defined_ exactly once (no more, no
less).

It sounds like what you're doing here is declaring the object multiple
times, but never defining it, so when DJGPP goes to the linker phase, it
discovers that the object has never been defined, and so complains. 
Similarly, when you removed all the extern keywords from those lines,
the linker found multiple definitions for the same object, and also
complained.

The way to fix it is to declare it in each module, but only define it in
_one_ module.  In short, remove the extern keyword from only one of the
modules in which it is declared.

-- 
Erik Max Francis / email max AT alcyone DOT com / whois mf303 / icq 16063900 
Alcyone Systems / irc maxxon (efnet) / finger max AT sade DOT alcyone DOT com
  San Jose, CA / languages En, Eo / web http://www.alcyone.com/max/
          USA / icbm 37 20 07 N 121 53 38 W / &tSftDotIotE
             \
            / An ounce of hypocrisy is worth a pound of ambition.
           / Michael Korda

- Raw text -


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