answersLogoWhite

0


Best Answer

No. The "inline" specifier is a hint to the compiler that the function so marked should be replaced, at each invocation, with its body. The compiler does not have to do so, and will refuse in certain cases. If it does honor the specifier, then you save the overhead of function call setup, entry, return, and cleanup, at the possible cost of larger object code size.

However, an inlined function body is subject to possible optimization, in the larger context of where it was placed, so inlining functions "can" optimize them, but that is not primarily what inlining means. Non-inlined functions are only optimized within the context of the function body.

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Does inline function inform the compiler to optimize calls to the function?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

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.


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.


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 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 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.


Does inline function increase the code size?

The inline specifier might increase the code size, but it might also reduce it.It depends on the size of the inlined function versus the overhead of setting up a stack frame and invoking the call/return sequence. Often, the inline specifier is used for very short, usually one line functions, and the intent is to sacrifice a bit of code size for execution size.Keep in mind that the inline specifier is only a compiler hint, and that the compiler may or may not actually inline the function, depending on context.


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.


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 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.


Advantage and disadvantage of inline function in c plus plus?

The advantage of an inline function is that it eliminates the function calls completely, thus improving the performance wherever those calls appear. The disadvantage is that it increases code size, which can be detrimental to performance. For this reason, declaring a function for inline expansion is merely a hint to the compiler. If the increased code size would be detrimental, the compiler is free to ignore the inline declaration and retain the function call instead. While the programmer is free to manually expand their own functions, this only serves to increase maintenance should the function ever need to be changed, and could lead to errors should those changes not be propagated correctly. The advantage of having a function, even if it is only ever called once (or from within a loop), is to simplify your code and make it easier to read and maintain. If the function is simple, or is called seldom, then it is a good candidate for expansion, but its almost always better to let the compiler decide which functions should be inline expanded.


What are the rules for inline functions in c plus plus?

When you mark function as inline compiler puts the whole body of function in those places it is called, similar idea as in macros. If you do not mark function as inlinecompiler inside still decides which functions should be inline and which not. Inline function is less performance costly especially if function is called very often. Why it is lest performance costly? Because to invoke function you need to prepare parameters, put them to stack, make jump and etc. and all those steps are eliminated if function is inline.Example (very basic):inline int sum(int a, int b) {return a + b;}int c, d;c = sum(2, 3); /* compiler will change to 2 + 3 */d = sum(2, 5); /* this one will be changed to 2 + 5 */Full inline functions are allowed in ANSI/ISO C99.


What is the difference between macro and inline function in c plus plus?

Macros are not actually part of the C++ language; they are nothing more than a simple text-replacement system intended to simplify your coding. Macros do not adhere to C++ type safety and cannot be debugged because macros are preprocessed, prior to compilation. Your compiler can only see the preprocessed code, not the original source code, and therefore cannot debug macros because the macros no longer exist at that point. Inline functions are functions that can be debugged like any other function, but the compiler is able to eliminate the overhead of function calla by replacing those calls with inline expanded code. This is not unlike a macro, which is by definition inline expanded, but retains the built-in type safety and debugging capabilities of the C++ language itself. Typically, if you can use an inline function (or C++ is general) then that is always the preferred option. But if a macro can achieve more than can be achieved with C++ alone, or can otherwise simplify the equivalent C++ code, then use a macro. Just keep in mind that macros are not type-safe and cannot be debugged by the C++ compiler.