How to know the inline-function was implemented the inline way or normal way?

Y

ypjofficial

Hello All,

Inline before a function definition is just a request to the compiler
to make the function inline.
The compiler may or maynot make it inline..
My question is ..is there any way by which I can find at runtime
whether the particular function which is marked as inline,is made
inline or is treated like other function by the compiler ?


Thanks and Regards,
Yogesh Joshi


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 
V

Victor Bazarov

Inline before a function definition is just a request to the compiler
to make the function inline.
The compiler may or maynot make it inline..

A function itself is just a collection of tokens. What is made inline
are the _calls_ to that function.
My question is ..is there any way by which I can find at runtime
whether the particular function which is marked as inline,is made
inline or is treated like other function by the compiler ?

Not portably.

V
 
T

Thomas Tutone

Inline before a function definition is just a request to the compiler
to make the function inline.
The compiler may or maynot make it inline..
My question is ..is there any way by which I can find at runtime
whether the particular function which is marked as inline,is made
inline or is treated like other function by the compiler ?

Not in any portable way. In any case, why do you need to find out at
_runtime_?

If you just wanted to find out at compile time, there are several
(nonportable) things you could do. First, many compilers will output
the assembly version of your compiled program, so you can manually
check. Of course, you would have to check again every time you
recompiled the program, since any changes could affect whether a
particualar inline request was honored by the compiler.

Second, some compilers will emit a warning if they fail to honor an
inline request. For example, in gcc, the "-Winline" command option
will emit a warning if the compiler does not inline a function that was
declared inline.

But that brings me back to my original question - why do you want to
find out at _runtime_?

Best regards,

Tom


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 
K

Kristo

Inline before a function definition is just a request to the compiler
to make the function inline.
The compiler may or maynot make it inline..
My question is ..is there any way by which I can find at runtime
whether the particular function which is marked as inline,is made
inline or is treated like other function by the compiler ?

The only way I can think to do that at all would be to read the
compiler-generated assembly code. As Victor said, there's definitely
no way to portably do it at runtime. A better question is why do you
care? Sometimes it's better if a function is *not* inlined. That's
why compilers are allowed to treat inline as a suggestion.

Kristo


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 
J

James Kanze

Inline before a function definition is just a request to the
compiler to make the function inline.
The compiler may or maynot make it inline..
My question is ..is there any way by which I can find at runtime
whether the particular function which is marked as inline,is made
inline or is treated like other function by the compiler ?

No. The question has no real meaning; a C++ program defines a
specific semantic, not a sequence of machine instructions. A
compiler may inline functions not declared inline (many do), not
inline a function declared inline, and generally not be
consistent about what it does---the same function may be
generated inline at one call site, and not at another. (At
least one compiler ignores the inline entirely, and uses
profiling information to decide where it inlines a function.)

--
James Kanze (e-mail address removed)
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France +33 (0)1 30 23 00 34

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 
T

Thomas Richter

Inline before a function definition is just a request to the compiler
to make the function inline.
The compiler may or maynot make it inline..
Right.

My question is ..is there any way by which I can find at runtime
whether the particular function which is marked as inline,is made
inline or is treated like other function by the compiler ?

First question: Why would you need to know? If your program depends on
this, then something's pretty wrong with your design.

If this is part of your optimization/profiling strategy:

A short answer would be that you would need to check the
assembly/machine code output of the compiler. There's no portable way of
checking whether the function got inlined or not.

Another answer would be to measure the running time of the program. If
it got faster, then the strategy of the compiler optimizing your code
improved by marking the function as "inline". Whether it then inlined
the code, or did something else, shouldn't matter - as long as the code
got faster. What else do you want? (-;

That said, I've observed programs that got slower by marking a function
as "inline".

So long,
Thomas

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 
G

Greg Herlihy

Hello All,

Inline before a function definition is just a request to the compiler
to make the function inline.
The compiler may or maynot make it inline..
My question is ..is there any way by which I can find at runtime
whether the particular function which is marked as inline,is made
inline or is treated like other function by the compiler ?

I would consult your C++ compiler's documentation to answer the
question as it pertains to your situation. Some C++ compilers can be
configured to issue a warning whenever a function declared inline is
not inlined for whatever reason (for example, the -Winline command line
option for the gcc compiler). As others have noted, the set of inlined
function calls in a program can be highly variable - therefore creating
dependencies on the inlined state of a particular function call is
probably not a recipe for stable development.

Greg


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 
M

Michiel.Salters

Hello All,

Inline before a function definition is just a request to the compiler
to make the function inline.
The compiler may or maynot make it inline..

Or only inline half a function. Or inline the entire function in some
places,
yet not inline it at all in others. Or not inline it, but pass the
parameters
in a different fashion. So "the answer" is not a single boolean answer.

HTH,
Michiel Salters


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,835
Latest member
KetoRushACVBuy

Latest Threads

Top