delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/11/17:31:03

From: triquet AT fil DOT univ-lille1 DOT fr (triquet frederic)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Help With Include Files.....PLEASE!
Date: 11 Feb 1997 13:48:33 GMT
Organization: Formations Informatiques Lille - F.I.L. - Bāt. M5
Lines: 59
Message-ID: <5dptbh$lcl@netserver.univ-lille1.fr>
References: <32ffba74 DOT 0 AT ntnews DOT compusmart DOT ab DOT ca>
Reply-To: triquet AT fil DOT univ-lille1 DOT fr
NNTP-Posting-Host: stu16.fil.univ-lille1.fr
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

In article <32ffba74 DOT 0 AT ntnews DOT compusmart DOT ab DOT ca>, demandrd AT compusmart DOT ab DOT ca (Demandred) writes:
+->SoMeOnE <bradh AT praxis DOT net> wrote:
+->
+->
+->You're probably not using inclusion guards.  Try putting this around
+->your code:
+->
+->#IFNDEF "foo_h"
+->#DEFINE "foo_h"
+->..
+->..
+->..
+->#ENDIF
+->
+->You can #DEFINE whatever you want, but the header filename is usually
+->easiest to remember.  Of course, if I did this wrong, it would explain
+->many bugs in my code =) but I'm afraid that's too easy an answer =).
+->

You shouldn't declare any variable in a "*.h" file: you'd better declare them
as 'extern' in this file and ( only once ) declare the vars in a '*.c'.

Why ?
Because declaring a var in a '*.h' declares it several times ( each time the '*.h'
is included )

Example:

in "hungry.h":
#ifdef HUNGRY_C
int my_var;
#else
extern int my_var;
#endif
:
:
:

and:

in "hungry.c":
#define HUNGRY_C
#include "hungry.h"
:
:
:



Hope this helps.


-- sorry for my poor english

				Fred.
Frederic Triquet
E-Mail: triquet AT fil DOT univ-lille1 DOT fr


- Raw text -


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