delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/10/14/04:19:57

Message-ID: <004501bdf74a$b91d7d00$a16f19c4@default>
From: rylan AT intekom DOT co DOT za (StefanViljoen,6599)
To: <djgpp AT delorie DOT com>
Subject: Re: Multi-modules
Date: Wed, 14 Oct 1998 10:12:01 +0200
MIME-Version: 1.0
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 4.72.2106.4
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4
Reply-To: djgpp AT delorie DOT com

-----Original Message-----
From: Gloria <lucjack AT golden DOT net>
Newsgroups: comp.os.msdos.djgpp
Cc: djgpp AT delorie DOT com <djgpp AT delorie DOT com>
Date: Wednesday, October 14, 1998 4:47 AM
Subject: Multi-modules


For my multi module programs, I declare global variables (like your
pointers) in the source file that contains the program's main() function.
Then, to make there variables globally visible, I create a .H file that
contains their prototypes as "extern" and then I include this .H file in ALL
the modules of the program that must have access to the global variables.
Like this:

Program consists of main.c mod1.c mod2.c  and the .H vars.h- with the int
"loop" that has to be accessible in all three, i. e. totally global to the
whole program:

[main.c]

#include "vars.h"

int loop, loop2;

int main()
{
 .
 .
 .
}

[mod1.c]

#include "vars.h"

void test()
{
 loop = 1;
}

[mod2.c]

#include "vars.h"

void test2()
{
 loop2 = 1;
}

[vars.h]

extern int loop,loop2 /*Defined in main.c, declared here to globally
accessible in all modules*/

Hope this helped!

Kind Regards,

Rylan
Is truth beauty or is beauty truth?
http://home.intekom.com/rylan/index.html


- Raw text -


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