671: Mainline
First, however, you should know a little about the proper and improper uses
of global variables. Here are a few
improper uses:
- It is possible to use a global variable to hold a constant such as
pi. This practice is usually a bad idea, because
constants are not supposed to change, yet you can certainly reassign a
global variable. You should introduce macro symbols using
#define
instead.
- It is possible to use a global variable to return information from a
function when there is more than one value to return. This practice is
usually a bad idea, because passing information out of a function
using global variable makes it hard to understand and control the
interaction between the calling function and the one that is called.
Instead, you should pass out information using pointer parameters, or you
should combine multiple values into a single structure object that is
returned in the ordinary way.
- It is possible to use a global variable to deliver information
from a calling function to a called function. This practice is
usually a bad idea, because passing information into a
function using global variable makes it hard to understand and
control the interaction between the calling function and the one
that is called. Instead, you should use ordinary arguments.