www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/10/22/05:15:12

From: Martin DOT Stromberg AT lu DOT erisoft DOT se (Martin Stromberg)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Doubly-defined variables
Date: 22 Oct 1998 10:06:24 GMT
Organization: Ericsson Erisoft AB, Sweden
Lines: 40
Message-ID: <70n030$ra5$1@antares.lu.erisoft.se>
References: <Pine DOT SGI DOT 3 DOT 95 DOT 981022101351 DOT 3325A-100000 AT tuomi DOT oulu DOT fi>
NNTP-Posting-Host: mars.lu.erisoft.se
X-Newsreader: TIN [version 1.2 PL2]
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Toni Rasanen (torasane AT mail DOT student DOT oulu DOT fi) wrote:

: Does anyone have any ideas why some of my variables seem to get
: defined two times, first occurance being in sources they
: definitely are not in...

: I use a .h -file to define the variables (a really stupid vay,
: but...), with #ifdefs trying to make sure they won't be defined
: again. In .h, there is nothing but variables (and they aren't 
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
: defined extern). I use those variables in various .c -files,
  ^^^^^^^^^^^^^^^^
: as they are global. Then I have in all .c's that use those
: variables 'vars.h' included... 

: eg.
: in 'main.c': #include "many_others.h"
:              #include "gfx.h"
:              #include "vars.h"
: in 'gfx.c':  #include <some_others.h"
:              #include "vars.h"

: However, when I try to compile this, compler tells me that some of
: (but not all!) the variables in vars.h are previously defined in some 
: other .c -file...

:  ///           Toni Räsänen
: ///       torasane AT mail DOT student DOT oulu DOT fi

Your problem is obviuos from the indicated line above. If you declare
variables in header files you really, really, _really_ should declare
them with "extern" and have the variable defined in one of your .c
files (without extern).

Read a good C book.


Right,

							MartinS

- Raw text -


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