answersLogoWhite

0


Best Answer

inline itself should be considered as a storage class

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why inline functions shall not be defined with extern or static storage class?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What are the disadvantages of inline functions?

The inline functions is an optimization technique that is used by the compilers. The disadvantage of the inline functions is the increased binary size.


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


In a header file whether functions are declared or defined?

Ideally, functions should only be declared in a header and defined in a translation unit (source file) that includes the header. However, trivial functions are often defined in a header as they are usually good candidates for inline expansion, but you must remember to declare the function inline. Often it is better to forward declare inline functions so that maintainers are not distracted by the implementation details which can be placed towards the end of the header, out of the way. However, a definition is also a declaration, so forward declaring an inline function is not a requirement unless there is a cyclic dependency issue where a forward declaration is necessary to break the cycle.


What is the advantage of an outline function?

Outline functions are primarily advantageous in debug code. By default, functions are never inline expanded in debug code (where NDEBUG is not defined) because debug code should never be optimised. This is simply because it much easier to map the assembly to the source code using outline functions.In release builds (where NDEBUG is defined), functions are only inline expanded when there is an advantage in doing so. Trivial one-line functions are good candidates, as are complex functions that are only invoked in one place. Functions that increase code size are rarely good candidates so these will remain outline functions. Note that the programmer has no real control over which functions will be inline expanded. In particular, the inlinekeyword has had no bearing on inline expansion since 1998; it is used solely as a linkage directive when defining a non-member function in a header.


Is inline function a command?

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


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 inline and const?

Everything. "inline" refers to functions, "const" refers to variables.


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.


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 use of INLINE function?

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 fileAn 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;}


How the member function can be defined?

Member functions can be defined in the declaration, or defined externally. Internal definitions are usually trivial functions, suitable for inline expansion. Non-trivial definitions are typically placed in a separate file, as per the following example: // File: obj.h class obj { public: void foo(){/* do something simple */} // internal definition. void bar(); }; // File: obj.cpp #include "obj.h" void obj.bar(){/* do something complicated */} // external definition.


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