Go to the first, previous, next, last section, table of contents.

Using Return Values

Always assign a return value to a variable before using it. This allows easier debugging of the function, and inspection and modification of the return value. If the variable is only needed temporarily then enclose it in a suitable scope.

For example, instead of writing,

a = f(g(h(x,y)))

use temporary variables to store the intermediate values,

{
  double u = h(x,y);
  double v = g(u);
  a = f(v);
}

These can then be inspected more easily in the debugger, and breakpoints can be placed more precisely. The compiler will eliminate the temporary variables automatically when the program is compiled with optimization.


Go to the first, previous, next, last section, table of contents.