From: Damian Yerrick Newsgroups: comp.os.msdos.djgpp Subject: Re: Global variables and structs? Organization: Pin Eight Software http://pineight.8m.com/ Message-ID: References: X-Newsreader: Forte Agent 1.7/32.534 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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" 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/