www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/02/16/07:07:57

From: Damian Yerrick <MYNAMEISd_yerrick AT hotmail DOT comNO2CANNEDHAM>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Global variables and structs?
Organization: Pin Eight Software http://pineight.8m.com/
Message-ID: <e2mkas4p5hlhkq852utnbmnmumo0k5f1mk@4ax.com>
References: <sak249572pd170 AT corp DOT supernews DOT com>
X-Newsreader: Forte Agent 1.7/32.534
MIME-Version: 1.0
Lines: 31
X-Trace: /bdhN4MtwfjFyWS3Kl5n2Y2BSdmCiar4X/eZSoASlqCGfNhlI1xqHw1nv71MQojkzgTzZqIywTlZ!Ze0gqekCR317m+k4+nuhU6Tfkw1e2VP/pG+7z3QYnqe8jIbWwptUuSFly4D4B7Mn9LVu7Y5z1+Hf!9g4WG8U=
X-Complaints-To: abuse AT gte DOT net
X-Abuse-Info: Please be sure to forward a copy of ALL headers
X-Abuse-Info: Otherwise we will be unable to process your complaint properly
NNTP-Posting-Date: Wed, 16 Feb 2000 08:00:04 GMT
Distribution: world
Date: Wed, 16 Feb 2000 08:00:04 GMT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

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.

>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.

-- 
Damian Yerrick  http://yerricde.tripod.com/
Comment on story ideas: http://home1.gte.net/frodo/quickjot.html
AOL is sucks! Find out why: http://anti-aol.org/faqs/aas/
View full sig: http://www.rose-hulman.edu/~yerricde/sig.html

This is McAfee VirusScan. Add these two lines to your .sig to
prevent the spread of .sig viruses.  http://www.mcafee.com/

- Raw text -


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