Can anybody tell that when Inline won't work though we have declared function as inline. i.e code replacement won't take place .

Recommended Answers

All 4 Replies

its totally up to the compiler whether it honors the inline keyword or not, and there is no way to force the compiler to do it one way or the other, except maybe make the inline code a macro.

*sniff* - smells like a homework question to me.

Here's one answer (for now) #define inline /* ha ha, no more in-lining today Jeeves */ I'll leave method number 2 for a day or so to add a sense of mystery and wonder (or merely just wait for someone else to post it).

inlining does not take place

in the presence (or absence) of some compiler switches / #pragma directives.
eg. presence of -fno-inline or -finline-limit=small_number / absence of -O in g++

for functions that are called using pointers obtained at runtime.
eg. C callbacks (the comparison function for qsort), C++ virtual functions called polymorphically

if the level of nested or recursive calls to inline functions goes above a certain implementation defined limit

>>inlining does not take place
And at the discrection of the compiler at all times. The compiler can decide to ignore inlining at all times if it wants to. inline is only a suggestion to the compiler, not a requirement that it has to honor.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.