delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/02/17/05:48:53

Date: Thu, 17 Feb 2000 11:56:31 +0600 (LKT)
From: Kalum Somaratna aka Grendel <kalum AT crosswinds DOT net>
X-Sender: root AT darkstar DOT grendel DOT net
To: djgpp AT delorie DOT com
Subject: Re: Global variables and structs?
In-Reply-To: <e2mkas4p5hlhkq852utnbmnmumo0k5f1mk@4ax.com>
Message-ID: <Pine.LNX.4.10.10002171151220.790-100000@darkstar.grendel.net>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
Errors-To: dj-admin AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Wed, 16 Feb 2000, Damian Yerrick wrote:

> On Tue, 15 Feb 2000 21:10:25 -0600, "William J. Urban II"
> <wjurban AT tca DOT net> wrote:
> 
> >Hello all,
> >    Well I am in a C++ class and also teaching myself some simple 2d game
> >writing with allegro.  Now, in class we learned about Global variables and
> >how we should use them sparingly.  My question is why?
> 
> It limits code reusability by causing potential namespace collisions.
> It limits stability by giving everything access to everything.

This is true but the calculated use of global variables can help to avoid
passing many arguments to functions. So using global variables can help to
simplify the code and also make it easier to understand. But IMHO this
should be done if you are confident with C/C++.


> 
> >I have a small move
> >the sprite around the screen program and every time I call the function to
> >update the screen I have to pass about 8 parameters.  I am thinking of
> >rewriting this tonight with global variables so that I dont have to keep
> >passing every single parameter.  Any thoughts on this?  Now I can understand
> >if its a variable like x but when its something specific that I wont use as
> >another variable like mapLocX than I don't understand why I shouldn't make
> >it global.  Thanks in advance.
> 
> Do it with structs.  Then you can pass a pointer to the struct and to
> the screen and be done with it.

Or better still use a global struct. That way you won't have to pass
anything at all and it will make writing the code easier.

HTH,
Kalum


> 
> This is McAfee VirusScan. Add these two lines to your .sig to
> prevent the spread of .sig viruses.  http://www.mcafee.com/
 ^^^^
Guess this "virus scan" is not working eh.... 

Hi, I'm a signature virus. plz set me as your signature and help me spread
:)

- Raw text -


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