Inline Functions

Another useful technique associated with program modularization with C++ functions is the use of inline functions. As you saw earlier, argument copying and context switching during the function call might affect the size of the stack memory that the program needs and its performance. These are important issues. When a function is small and is called often from functions with a large number of local variables, it is a pity to waste time and stack memory for saving the caller environment for the sake of executing a few lines of code.

Consider, for example, the function that computes tax by using a constant coefficient.

double tax(double gross)
{ return gross * 0.05; }

When the client code calls this function, the "context" of ...

Get Core C++ A Software Engineering Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.