< previous page page_401 next page >

Page 401
deposit results into the caller's actual parameters is to have the addresses of those parameters. For emphasis, we repeat the following table from Chapter 7.
Data Flow for a ParameterParameter-Passing Mechanism
IncomingPass-by-value
OutgoingPass-by-reference
Incoming/outgoingPass-by-reference

As we said in the last chapter, there are exceptions to the guidelines in this table. C++ requires that I/O stream variables be passed by reference because of the way streams and files are implemented. We encounter another exception in Chapter 11.
Sometimes it is tempting to skip the interface design step when writing a function, letting it communicate with other functions by referencing global variables. Don't! Without the interface design step, you would actually be creating a poorly structured and undocumented interface. Except in welljustified circumstances, the use of global variables is a poor programming practice that can lead to program bugs. These bugs are extremely hard to locate and usually take the form of unwanted side effects.
Side Effects
Suppose you made a call to the sqrt library function in your program:
y = sqrt(x);
You expect that the call to sqrt will compute the square root of the variable x. You'd be surprised if sqrt also changed the value of your variable x because sqrt, by definition, does not make such changes. This would be an example of an unexpected and unwanted side effect.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif 3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Side Effect Any effect of one function on another that is not a part of the explicitly defined interface between them.
Side effects are sometimes caused by a combination of reference parameters and careless coding in a function. Perhaps an assignment statement in

 
< previous page page_401 next page >