Define inline functions, C/C++ Programming

Assignment Help:

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.

 


Related Discussions:- Define inline functions

Write a program that finds the minimum total number of she., Write a progra...

Write a program that finds the minimum total number of shelv, C/C++ Programming

Calculate the average assignment grade, 1. The main program must be in a fi...

1. The main program must be in a file called A4.cpp 2. The data must be read in from a data file.  The user must enter the filename.  A sample data file will be provided on Mood

Area under curve, write a program to find the area under curve y=f(x) betwe...

write a program to find the area under curve y=f(x) between x=a and x=b,integrate y=f(x) between the limits a and b

What are compound statements, What are compound statements? - Compound ...

What are compound statements? - Compound statements are made up of two or more program statements that are executed together. They may be executed with a loop. - Curly brack

How are postfix and prefix versions of operator++ , How are postfix and pre...

How are postfix and prefix versions of operator++ () differentiated? A: The postfix version of operator++ () contain a dummy parameter of type int. The prefix version does not c

C program for bubble sort, C program for bubble sort: void main() {...

C program for bubble sort: void main() { int i,j,k,a[10],n; clrscr(); printf("How many values you want to enter\n"); scanf("%d",&n);  for(i=0;i  {  pri

Working with files in cpp, Operation Files 2.1. Your program should open an...

Operation Files 2.1. Your program should open and read the file specified by the first command line argument of the program. 2.2. The first line of the file contains an integer

Write a program to create a binary file, Write a program to create a binary...

Write a program to create a binary file and store the following data "hello", 0x0030,'1', 1.234  Using visual studio examine the binary file and note how the day is stored   Answe

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd