delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/02/17/22:24:33

Date: Fri, 18 Feb 2000 05:31:33 +0600 (LKT)
From: Kalum Somaratna aka Grendel <kalum AT crosswinds DOT net>
X-Sender: root AT darkstar DOT grendel DOT net
To: Prashant TR <prashant_tr AT yahoo DOT com>
cc: djgpp AT delorie DOT com
Subject: Re: Global variables and structs?
In-Reply-To: <Pine.LNX.4.10.10002172257490.790-100000@midpec.com>
Message-ID: <Pine.LNX.4.10.10002180522340.772-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 Thu, 17 Feb 2000, Prashant TR wrote:

> On Thu, 17 Feb 2000, Kalum Somaratna aka Grendel wrote:
> 
> > 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++.
> 
> Doesn't help most of the times, but creates a nuisance instead. It's a bad
> practice to do this. Things like this can be used only for a single
> program, certainly not for a large project.

BTW Global variables were used extensively in ID softwares games like
Wolfenstein 3D.

Consider you are writing a game and you have a global structure which
contains info about the player. The player stucture will have to be
acessed by a lot of functions and since it is global there is no need to
pass it as a argument to every routine that needs to acesss it, thus
simplifying matters/code a lot.

So IMHO _calculated_ not _haphazard_ use of global variables should be
done especially in large projects.


> 
> > > 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.
> 
> Don't think this is a good idea. What Damian has said would get you a
> better program. If the array is too large, consider using malloc.
> 

Please see my above message and consider whether a structure which
contains info about the screen (dimensions, bpp etc) would be better of as
a global variable or not.

It should be easier when it is a global variable as you wont have to  pass
it to every func every time you wanted to acess it..

Grendel.

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