Function inlining

Discussion in 'C Programming' started by Ian, Jan 14, 2006.

  1. Ian

    Ian Guest

    This is partly related to the kernel C/C++ thread, one thing I'm not
    sure about with modern C compiler is how aggressively they inline
    trivial functions as an optimisation.

    A C++ compiler will be fairly aggressive in this area, so it is
    generally safe to assume that short functions will get inlined away as
    this tends to improve both code size and execution speed.

    Do modern C compilers do the same?

    Cheers,

    Ian.
    Ian, Jan 14, 2006
    #1
    1. Advertising

  2. On Sun, 15 Jan 2006 10:07:50 +1300, in comp.lang.c , Ian
    <> wrote:

    (of optimisation)

    >Do modern C compilers do the same?


    This is not topical here, since it depends on the compiler not on the
    language. For an authorative answer you'd need to ask in groups
    specialising in various compilers. Offhand however I'd simply point
    out that most compiler suites these days contain C and C++ tools from
    the same source and it'd be pretty bizarre not to perform similar
    optimizations in your two offerings.
    Mark McIntyre
    --

    ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
    Mark McIntyre, Jan 14, 2006
    #2
    1. Advertising

  3. Ian

    Jack Klein Guest

    On Sun, 15 Jan 2006 10:07:50 +1300, Ian <> wrote
    in comp.lang.c:

    > This is partly related to the kernel C/C++ thread, one thing I'm not
    > sure about with modern C compiler is how aggressively they inline
    > trivial functions as an optimisation.
    >
    > A C++ compiler will be fairly aggressive in this area, so it is
    > generally safe to assume that short functions will get inlined away as
    > this tends to improve both code size and execution speed.
    >
    > Do modern C compilers do the same?


    First, please use a proper signature delimiter, like mine at the
    bottom. It consists of "-- ". Most newsreaders recognize this and
    provide proper handling automatically.

    Second, what is your definition of "modern C compilers"? Optimization
    is both inherently implementation specific, and not defined by the C
    standard. If you want to know about the behavior of specific
    compilers, as in their compiler specific support groups or try them
    yourself.

    Note that compilers that support the 1999 or later versions of the C
    standard recognize the inline keyword to specifically suggest to the
    compiler that you want a particular function inlined. Just as with
    the register keyword, the compiler is free to ignore your request.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://c-faq.com/
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
    Jack Klein, Jan 15, 2006
    #3
  4. Ian

    Ian Collins Guest

    Jack Klein wrote:
    > On Sun, 15 Jan 2006 10:07:50 +1300, Ian <> wrote
    > in comp.lang.c:
    >
    >
    >>This is partly related to the kernel C/C++ thread, one thing I'm not
    >>sure about with modern C compiler is how aggressively they inline
    >>trivial functions as an optimisation.
    >>
    >>A C++ compiler will be fairly aggressive in this area, so it is
    >>generally safe to assume that short functions will get inlined away as
    >>this tends to improve both code size and execution speed.
    >>
    >>Do modern C compilers do the same?

    >
    >
    > First, please use a proper signature delimiter, like mine at the
    > bottom. It consists of "-- ". Most newsreaders recognize this and
    > provide proper handling automatically.
    >

    OK, done.

    > Second, what is your definition of "modern C compilers"? Optimization
    > is both inherently implementation specific, and not defined by the C
    > standard. If you want to know about the behavior of specific
    > compilers, as in their compiler specific support groups or try them
    > yourself.
    >
    > Note that compilers that support the 1999 or later versions of the C
    > standard recognize the inline keyword to specifically suggest to the
    > compiler that you want a particular function inlined. Just as with
    > the register keyword, the compiler is free to ignore your request.
    >

    It's been a while since I've studied compiler output on embedded
    systems, but when I was working in this area, we had to resort to macros
    rather than short functions because our compiler didn't inline trivial
    functions.

    I was simply curious about the current state of the art.

    --
    Ian Collins.
    Ian Collins, Jan 15, 2006
    #4
    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. Ronald Fischer
    Replies:
    3
    Views:
    563
    Roedy Green
    Jul 20, 2004
  2. Alex
    Replies:
    6
    Views:
    409
  3. Gianni Mariani

    inlining function objects

    Gianni Mariani, Feb 23, 2004, in forum: C++
    Replies:
    7
    Views:
    377
  4. Mat Booth

    Function Pointers and Inlining

    Mat Booth, Mar 22, 2005, in forum: C++
    Replies:
    8
    Views:
    354
    Rolf Magnus
    Mar 22, 2005
  5. Replies:
    5
    Views:
    453
Loading...

Share This Page