Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > How to know the inline-function was implemented the inline way or normal way?

Reply
Thread Tools

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

 
 
ypjofficial@indiatimes.com
Guest
Posts: n/a
 
      07-14-2006
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! ]

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      07-14-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
 
 
 
Thomas Tutone
Guest
Posts: n/a
 
      07-15-2006
(E-Mail Removed) wrote:

> 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! ]

 
Reply With Quote
 
Kristo
Guest
Posts: n/a
 
      07-15-2006
(E-Mail Removed) wrote:
> 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! ]

 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      07-15-2006
(E-Mail Removed) wrote:

> 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 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! ]

 
Reply With Quote
 
Thomas Richter
Guest
Posts: n/a
 
      07-15-2006
(E-Mail Removed) wrote:

> 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! ]

 
Reply With Quote
 
Greg Herlihy
Guest
Posts: n/a
 
      07-17-2006

(E-Mail Removed) wrote:
> 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! ]

 
Reply With Quote
 
Michiel.Salters@tomtom.com
Guest
Posts: n/a
 
      07-18-2006
(E-Mail Removed) wrote:
> 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! ]

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
when "normal" parallel computations in CPython will be implemented at last? dmitrey Python 7 07-02-2012 06:37 PM
why inline is faster than normal function call? thomas C++ 2 11-13-2009 04:47 PM
I know, I know, I don't know Andries Perl Misc 3 04-23-2004 02:17 AM
inline or not to inline in C++ Abhi C++ 2 07-03-2003 12:07 AM



Advertisments