Tuesday 16 December 2014

inline to reduce transitions between function calls

inline is a keyword to execute a particular function repeatedly in inline fashion.

This concept comes into role to reduce the code size.

Actually code size not reduced. Number of lines of program can be reduced.

Requesting the compiler to replace the function body in the calling function place is called inline.

Benefits of inline keyword: 

1) Number of transitions between calling function and called function can be reduced.

2) Same stack memory can be used.
Rules to follow while using inline keyword:

1) Inline functions has to be defined before it is calling.

2) Inline is a request. It’s not an order.

3) There is no 100% guarantee that, inline requested functions will execute in inline fashion itself only.

4) Inline function should not contain any looping statements.

Here the compiler takes many number of transitions. Due to this, lot of time of CPU will get wasted. To avoid this, we have to use inline keyword.
Here number of transitions reduced and the same stack memory used.

Macro’s only replaces the code. Macro’s doesn’t know the passing parameters type.

C++ compiler enhanced the functions compared to C compiler.

Some times we can’t able to get exact results in C for macro related operations. But this problem can be


achieved by using inline keyword in C++. By using inline we can achieve exact results.