Q:

What is the advantage and disadvantage of the inline function?

0

What is the advantage and disadvantage of the inline function?

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Answer:

There are a few important advantages and disadvantages of the inline function.

Advantages:-
1) It saves the function calling overhead.
2) It also saves the overhead of variables push/pop on the stack, while function calling.
3) It also saves the overhead of return call from a function.
4) It increases the locality of reference by utilizing the instruction cache.
5) After inlining compiler can also apply intraprocedural optimization if specified. This is the most important one, in this way compiler can now focus on dead code elimination, can give more stress on branch prediction, induction variable elimination, etc..

Disadvantages:-
1) May increase function size so that it may not fit in the cache, causing lots of cache miss.
2) After the inlining function, if variables numbers that are going to use register increases then they may create overhead on register variable resource utilization.
3) It may cause compilation overhead as if somebody changes code inside an inline function then all calling locations will also be compiled.
4) If used in the header file, it will make your header file size large and may also make it unreadable.
5) If somebody used too many inline functions resultant in a larger code size then it may cause thrashing in memory. More and number of page faults bringing down your program performance.
6) It’s not useful for an embedded system where a large binary size is not preferred at all due to memory size constraints.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Embedded C interview questions and answers (2022)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
What is virtual memory?... >>
<< What is the inline function?...