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

Discussion in 'C++' started by ypjofficial@indiatimes.com, Jul 14, 2006.

  1. Guest

    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! ]
    , Jul 14, 2006
    #1
    1. Advertising

  2. 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
    Victor Bazarov, Jul 14, 2006
    #2
    1. Advertising

  3. 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! ]
    Thomas Tutone, Jul 15, 2006
    #3
  4. Kristo Guest

    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! ]
    Kristo, Jul 15, 2006
    #4
  5. James Kanze Guest

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

    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
    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! ]
    James Kanze, Jul 15, 2006
    #5
  6. Re: How to know the inline-function was implemented the inline way or normal way?

    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! ]
    Thomas Richter, Jul 15, 2006
    #6
  7. Greg Herlihy Guest

    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! ]
    Greg Herlihy, Jul 17, 2006
    #7
  8. Guest

    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! ]
    , Jul 19, 2006
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Morgan Cheng
    Replies:
    4
    Views:
    616
    Morgan Cheng
    Dec 17, 2004
  2. TGOS
    Replies:
    3
    Views:
    370
    Kevin Bracey
    Feb 28, 2005
  3. thomas
    Replies:
    2
    Views:
    402
    Victor Bazarov
    Nov 13, 2009
  4. Andries

    I know, I know, I don't know

    Andries, Apr 23, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    223
    Gregory Toomey
    Apr 23, 2004
  5. dmitrey
    Replies:
    7
    Views:
    250
    Stefan Behnel
    Jul 2, 2012
Loading...

Share This Page