Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inline Functions

I know compiler may or may not perform inline expansion of a function whether requested by the programmer or not.
I was just curious to know, is there any way by which programmer can know for sure that compiler has inlined a particular function?

like image 597
Rajendra Uppal Avatar asked Mar 05 '10 04:03

Rajendra Uppal


People also ask

What is inline function?

An inline function is one for which the compiler copies the code from the function definition directly into the code of the calling function rather than creating a separate set of instructions in memory. This eliminates call-linkage overhead and can expose significant optimization opportunities.

What is inline function and example?

Inline function is a function that is expanded in line when it is called. When the inline function is called whole code of the inline function gets inserted or substituted at the point of inline function call. This substitution is performed by the C++ compiler at compile time.

What is an inline function in C++?

Inline function in C++ is an enhancement feature that improves the execution time and speed of the program. The main advantage of inline functions is that you can use them with C++ classes as well.

What is inline function and its advantages?

Inline function instruct compiler to insert complete body of the function wherever that function got used in code. Advantages :- 1) It does not require function calling overhead. 2) It also save overhead of variables push/pop on the stack, while function calling. 3) It also save overhead of return call from a function.


1 Answers

Other than by looking at the generated code, no. Some implementations may provide that information but it's not required by the standard.

Things like inline or register (shudder) are suggestions to the compiler and it's free to accept them, ignore them or even lie to you that it's done it while secretly going behind your back and not doing it :-)

I tend not to use features like that since I suspect the compiler often knows better than I do how to wring the most performance out of my code.

like image 192
paxdiablo Avatar answered Sep 23 '22 19:09

paxdiablo