answersLogoWhite

0

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.

User Avatar

Wiki User

16y ago

What else can I help you with?

Continue Learning about Engineering

Why inline function cannot be static?

Inline functions can be static. However, their usage outside of classes in C++ has been deprecated (a hangover from C). Static member functions are allowed of course, and they can be inline expanded where desired. In C, a static function simply has limited scope within the same translation unit. In C++, unnamed namespaces are the preferred method of achieving the same end.


How does the inline mechanism in C reduce the run-time overheads?

inline functions are compiled very fastly and uses the free memory to boot it as soon as possible


Why functions are not used in c plus plus?

Of course they are used. Both stand-alone and class-member functions are used in C++.


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.


How do you convert from assembly to binary in c plus plus?

Use inline assembly instructions. Then compile your C++ program to produce the machine code.

Related Questions

Automatic inline in c plus plus?

The C++ compiler will implicitly (automatically) mark functions for inline expansion whenever you define a function within its own declaration. If functions are declared and defined separately (even in the same file) then they are not implicitly marked for inline expansion. To enable inline expansion for these definitions, you must explicitly mark the definition (not the declaration).


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

yes,we can make function inline


How are the graphs of functions defined by rules like y equals ax plus bx different from those of functions with rules like y equals ax plus c?

The graph of the first form passes through the origin while the second does not - unless c = 0.


Can there be friend functions in c plus plus?

Yes, there can be friend functions in C++.


Inline functions in c plus plus with prgram example?

#include<iostream> using namespace std; inline int max(int a,int b) { return (a>b)?a:b; } int main() { int i1=3,i2=5; cout<<endl<<"Inline function says max is "<<max(i1,i2); return 0; } /* Usually when a function is called, the compiler goes to the particular piece of code and executes it. But in the case of inline functions, the code from the body of the function is effectively pasted at the point of call. inline functions are used when the body of the function is only a line or so.*/


Why inline function cannot be static?

Inline functions can be static. However, their usage outside of classes in C++ has been deprecated (a hangover from C). Static member functions are allowed of course, and they can be inline expanded where desired. In C, a static function simply has limited scope within the same translation unit. In C++, unnamed namespaces are the preferred method of achieving the same end.


Printf and scanf Operators in C and C plus plus?

No, they are functions. Operators are -> or ++or /=


How does the inline mechanism in C reduce the run-time overheads?

inline functions are compiled very fastly and uses the free memory to boot it as soon as possible


Why functions are not used in c plus plus?

Of course they are used. Both stand-alone and class-member functions are used in C++.


What is a method in c plus plus?

In C++, methods are simply class member functions.


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.


How do you convert from assembly to binary in c plus plus?

Use inline assembly instructions. Then compile your C++ program to produce the machine code.