l i n u x - u s e r s - g r o u p - o f - d a v i s
Next Meeting:
July 7: Social gathering
Next Installfest:
Latest News:
Jun. 14: June LUGOD meeting cancelled
Page last updated:
2002 Sep 20 12:57

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] global variables in C
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] global variables in C

On Fri, Sep 20, 2002 at 10:34:51AM -0700, Peter Jay Salzman wrote:
> 1. name clashing
> 2. readability

These are good reasons.

I'm pretty bad about using globals all over the place, though.

My main reason, however, _is_ for readability.

In _most_ cases, the functions I'm calling need to do things to,
or refer to, the same variables over and over again.

As an example, in my games I open the SDL window surface and name it

Rather than having to pass "screen" around to ALL of the functions
(first retrieving it from my "setup()" function), I prefer to keep it

Everyone uses it, it's simpler for me to just leave it 'out there'
for them to use.  Sure, _some_ functions won't use it, but it's
a lot less cluttery to do something like:



Than it is:

  draw_spaceship(screen, spaceship_x, spaceship_y, spaceship_dir,

  draw_aliens(screen, aliens_array, NUM_ALIENS);

It's not like this 'abstraction' of the functions benefits me.

I'll rarely, if ever, call "draw_spaceship()" and tell it to draw
the spaceship on some OTHER surface, or at some OTHER X/Y coordinate
than where the spaceship actually _is_! ;)

IANACG (I am not a C guru), YMMV (your milage may vary),
UAYOR (use at your own risk), GATAA (geez, aren't these acronyms annoying?)


vox-tech mailing list

LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
Sunset Systems
Who graciously hosts our website & mailing lists!