inline functionsimagine a c program which reads


Inline Functions

Imagine a c program, which reads disk records having employee information. If this is a payroll application each employee record data is probably processed by a series of function calls. These function calls could be to print the entity data, to compute the salary, to compute the taxes to be withheld etc,. Every one of these calls inherently contains overhead that must be part of your overall program. In other words it takes code space and time to push actual arguments onto the stack, call the function, push some return value onto the stack and finally pop all of those values.

C++ gives the inline functions, a mechanism by which these explicit function calls can be avoided.

"An inline function by definition is a function whose code gets substituted in place of the actual call to that function."

Whenever the compiler encounters a call to that function it merely replaces it with the code itself thereby saving you all of the overhead.  Such a function can be either a member of a class or a global function. Inline functions work best when they are small, straightforward bodies of code that are not called from too many dissimilar places within your program. The time saved will enhance with the increase in number of calls.

Even if you request that the compiler make a function into an inline function, the compiler may or may not honour that request.  It depends on the code of the function.  For instance, the compiler will not inline any function that contains a loop, static data member, or aggregate initializer list.  If such cases case, a warning message will be issued.

The drawbacks with inline functions is that if the code itself ever needs to be modified, then all programs that use the these functions would then have to be recompiled.  Moreover, an inline function is a violation of implementation hiding.

 

Request for Solution File

Ask an Expert for Answer!!
C/C++ Programming: inline functionsimagine a c program which reads
Reference No:- TGS0309479

Expected delivery within 24 Hours