Mail Archives: djgpp/1998/10/14/01:55:23
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 -