answersLogoWhite

0

What is the use of INLINE function?

Updated: 8/10/2023
User Avatar

Wiki User

10y ago

Best Answer

it is the function declared inside the class. It is used for gaining faster speed in execution but it might give back the larger executable file
An inline function is one that is not called, its code is inserted in the position where you make a call to it. If it is called multiple times from different locations it was be inserted in all locations, increasing the size of all functions its called from but marginally increasing speed.

Take this example:

inline int AddNumbers(int a,int b)

{

return a+b;

}

int main()

{

int x = 2;

int y = 3;

int answer;

answer = AddNumbers(x,y);

answer = AddNumbers(answer,y);

return 0;

}

When the program is compiled it would look more like this:

int main()

{

int x = 2;

int y = 3;

int answer = x+y;

answer += y;

return 0;

}

User Avatar

Wiki User

10y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

10y ago

An inline function is a function that is inline expanded in your code during compilation, thus eliminating the overhead of a function call, whilst retaining the function itself for the purpose of code maintenance and readability. Declaring a function inline is no guarantee that it will be inline expanded, however. The compiler will ultimately decide if the performance gained from inline expansion is sufficient to compensate for any increase in code size. Inline expansion is ideally suited to small, simple functions, such as class accessors (getters) which merely return values, or functions that perform simple arithmetic. However, complex functions that are only called once are also suitable candidates, as are recursive functions with limited depth.

This answer is:
User Avatar

User Avatar

Wiki User

6y ago

Functions that are defined in a header are inline functions.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the use of INLINE function?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What happens if recursion function is declared inline?

An inline function replaces the call to the function by the body of the function, thus reducing the overhead of saving the context in stack. This is good for functions which are small in size and called occasionally. A recursive function calls an instance of itself and thus can be a deeply nested. Different compilers handle this differently. Some will inline it up to a certain depth and then call a non-inlined instance for further recursion; others will not inline the function at all and generate a normal function call.


What is outline function in c plus plus language?

Outline is the opposite of inline. An inline expanded function is any function or class method where the declaration also provides the definition (the implementation). This is known as implicit inline expansion. Where the definition is kept separate from the declaration, you may use the inline keyword to specifiy that the function should be inline. This is known as explicit inline expansion. Inline expanded functions (whether implied or explicit) does NOT mean the function will in fact be inline expanded. It is merely a suggestion to the compiler. If the compiler's optimisers determine that there is no advantage to be gained by inline expanding a particular function, then that function becomes an outline function. Inline expansion simply means that the body of the function is inserted in place of the function call. Function calls are expensive in terms of memory and performance, so by eliminating the function call completely, your code performs faster and uses less memory. However, functions that are called many times throughout your code will result in a much larger code size, and large code runs slower than small code. Thus the benefit of eliminating a function call has to be weighed against the increased code size. Although some compilers do allow you to override the compiler's inline expansion optimisers, this is strictly non-standard. The best judge of what to expand and what not to expand is best left in the hands of the compiler, and indiscriminate use of the inline keyword should generally be avoided.


What is inline function in C Can you make inline function recursive or not If make can complier will compile that code?

The inline attribute is a C++ attribute, not a C attribute. Inline specifies that the function is to be expanded in place at the point of call instead of being called as a function. This means there will be one copy of the function for each call. This costs executable code, but can save execution time because the call setup and return time is avoided. Some functions cannot be inlined, and inline is really only a hint to the compiler. As far as recursive inlined functions, that depends on the implementation. The Microsoft implementation will not inline recursive functions unless they have a #pragma inline depth(n) line that specifies the maximum recusion depth the function will have. Consult your specific compiler documentation for the inline attribute for your specific implementation details.


When will you make inline function?

Trivial functions, such as member variable accessors that simply return a member's value, are prime candidates for inline expansion. However trivial non-member functions can also be inline expanded, as can any non-trivial function that is rarely called.Member functions defined in the body of the class declaration are implicitly declared inline. However, whether a function is explicitly declared inline or not, the compiler is free to ignore any inline request, such as when the inline expansion of a non-trivial function would adversely compromise code size, for instance.Note that inline expansion replaces the call to a function with a modified version of the function's body within the calling functions -- just as if you'd duplicated the code yourself, rather than creating a separate function -- which removes the overhead of making a function call.The only way to force a function inline is to manually write the expanded code yourself. But if the code appears in several places, maintenance of the code will be compromised.If there's ever any doubt, declare it inline and let the compiler decide. It's in a far better position to determine if it should be inline expanded or not.


What is the difference between inlinefunction and function overloading?

The normal way a function works is that whenever your code encounters a call to the function, it jumps to the body of the function code. An inline function tells the compiler that it should actually copy over the code from a function body into all places where that function is called. In some cases this can cause a dramatic reduction in run time, but in others it causes nothing more than increasing the size of the produced executable. Function overloading refers to the ability to have multiple functions with the same name, but different parameter types.

Related questions

When will you make a function inline in c plus plus?

yes,we can make function inline


What happens if recursion function is declared inline?

An inline function replaces the call to the function by the body of the function, thus reducing the overhead of saving the context in stack. This is good for functions which are small in size and called occasionally. A recursive function calls an instance of itself and thus can be a deeply nested. Different compilers handle this differently. Some will inline it up to a certain depth and then call a non-inlined instance for further recursion; others will not inline the function at all and generate a normal function call.


What is outline function in c plus plus language?

Outline is the opposite of inline. An inline expanded function is any function or class method where the declaration also provides the definition (the implementation). This is known as implicit inline expansion. Where the definition is kept separate from the declaration, you may use the inline keyword to specifiy that the function should be inline. This is known as explicit inline expansion. Inline expanded functions (whether implied or explicit) does NOT mean the function will in fact be inline expanded. It is merely a suggestion to the compiler. If the compiler's optimisers determine that there is no advantage to be gained by inline expanding a particular function, then that function becomes an outline function. Inline expansion simply means that the body of the function is inserted in place of the function call. Function calls are expensive in terms of memory and performance, so by eliminating the function call completely, your code performs faster and uses less memory. However, functions that are called many times throughout your code will result in a much larger code size, and large code runs slower than small code. Thus the benefit of eliminating a function call has to be weighed against the increased code size. Although some compilers do allow you to override the compiler's inline expansion optimisers, this is strictly non-standard. The best judge of what to expand and what not to expand is best left in the hands of the compiler, and indiscriminate use of the inline keyword should generally be avoided.


Is inline function a command?

No, functions (inline or other) aren't commands.


Difference between normal function inline function?

gffg


What is the difference between an outline and inline?

For the inline functions compiler just copies the function code in that place and when the size is too big it treats that function as ordinary function.


Which keyword is used to make function call faster in c?

Inline Function


When make a function inline?

Trivial functions, such as member variable accessors that simply return a member's value, are prime candidates for inline expansion. However trivial non-member functions can also be inline expanded, as can any non-trivial function that is rarely called.Member functions defined in the body of the class declaration are implicitly declared inline. However, whether a function is explicitly declared inline or not, the compiler is free to ignore any inline request, such as when the inline expansion of a non-trivial function would adversely compromise code size, for instance.Note that inline expansion replaces the call to a function with a modified version of the function's body within the calling functions -- just as if you'd duplicated the code yourself, rather than creating a separate function -- which removes the overhead of making a function call.The only way to force a function inline is to manually write the expanded code yourself. But if the code appears in several places, maintenance of the code will be compromised.If there's ever any doubt, declare it inline and let the compiler decide. It's in a far better position to determine if it should be inline expanded or not.


What is inline function in C Can you make inline function recursive or not If make can complier will compile that code?

The inline attribute is a C++ attribute, not a C attribute. Inline specifies that the function is to be expanded in place at the point of call instead of being called as a function. This means there will be one copy of the function for each call. This costs executable code, but can save execution time because the call setup and return time is avoided. Some functions cannot be inlined, and inline is really only a hint to the compiler. As far as recursive inlined functions, that depends on the implementation. The Microsoft implementation will not inline recursive functions unless they have a #pragma inline depth(n) line that specifies the maximum recusion depth the function will have. Consult your specific compiler documentation for the inline attribute for your specific implementation details.


When will you make inline function?

Trivial functions, such as member variable accessors that simply return a member's value, are prime candidates for inline expansion. However trivial non-member functions can also be inline expanded, as can any non-trivial function that is rarely called.Member functions defined in the body of the class declaration are implicitly declared inline. However, whether a function is explicitly declared inline or not, the compiler is free to ignore any inline request, such as when the inline expansion of a non-trivial function would adversely compromise code size, for instance.Note that inline expansion replaces the call to a function with a modified version of the function's body within the calling functions -- just as if you'd duplicated the code yourself, rather than creating a separate function -- which removes the overhead of making a function call.The only way to force a function inline is to manually write the expanded code yourself. But if the code appears in several places, maintenance of the code will be compromised.If there's ever any doubt, declare it inline and let the compiler decide. It's in a far better position to determine if it should be inline expanded or not.


What is the difference between inlinefunction and function overloading?

The normal way a function works is that whenever your code encounters a call to the function, it jumps to the body of the function code. An inline function tells the compiler that it should actually copy over the code from a function body into all places where that function is called. In some cases this can cause a dramatic reduction in run time, but in others it causes nothing more than increasing the size of the produced executable. Function overloading refers to the ability to have multiple functions with the same name, but different parameter types.


Is inline functions inform your compiler to optimize calls to the function?

No. The inline keyword simply tells the compiler that the function is a candidate for inline expansion. If the compiler's optimisers approve inline expansion, the function body is inline expanded at each call site, thus completely eliminating the overhead of the function calls at the expense of increased code size. If the increased code size would be detrimental to performance, the inline expansion is ignored completely. Note that functions that are defined within their own declarations are implicitly marked for inline expansion, thus the inline keyword should only be used where interfaces are declared separately (usually in header files) from their implementations (usually in source files). Also note that inline expansion is only suitable for small functions with one or two simple statements at most, or larger functions that are seldom called. Recursive functions can also be inline expanded, however the compiler will limit the depth of the calls. Any subsequent recursions will be treated as being standard function calls. However, most compilers also make use of tail recursion optimisers to minimise call depths.