cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1999/07/30/08:28:12

From: star_traveler4 AT hotmail DOT com
Newsgroups: comp.os.msdos.djgpp
Subject: Global vars in C++
Date: Fri, 30 Jul 1999 07:40:34 GMT
Organization: An Internet Solution Customer
Lines: 51
Message-ID: <37a15553.9035233@news.sasol.com>
NNTP-Posting-Host: gauntlet.sasol.com
X-Newsreader: Forte Free Agent 1.11/32.235
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Hi !

I'm quite new to c++, and I have the following problem:

I have a global variable,  which I defined in a header file.  I have
two .c programs that use this header file.  The programs look like
this:

Johann.h:
#ifndef _JOHANN_H_
#define _JOHANN_H_
   int TheValue;
#endif


Johann.c:
#include <stdio.h>
#include "johann.h"

void DoTest();

int main()
{
   TheValue = 25;
   DoTest();
   return 0;
}


Johann2.c:

#include <stdio.h>
#include "johann.h"

void DoTest()
{
   printf("The value is: %d\n",TheValue);
}


I compile them using:

gcc -Wall -o johann.exe johann.c johann2.c.  This works fine.  

However, when I try this using gxx, like this:
gxx -Wall -o johann.exe johann.c johann2.c, I get an error message
that 'TheValue' is already defined.  How do you create global
variables in c++ then?

Kind regards,
Johann  

- Raw text -


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