C Inlining

Discussion in 'C Programming' started by Bill Cunningham, Oct 5, 2003.

  1. What is C inlinging? Or inlining. Does it have something to do with using C
    and assembly language together? I know some of the linux kernel is inlined
    and it's written in C with a little assembly.

    Bill





    -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
    http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
    -----== Over 100,000 Newsgroups - 19 Different Servers! =-----
     
    Bill Cunningham, Oct 5, 2003
    #1
    1. Advertising

  2. Bill Cunningham

    -berlin.de Guest

    Bill Cunningham <> wrote:
    > What is C inlinging? Or inlining. Does it have something to do with using C
    > and assembly language together? I know some of the linux kernel is inlined
    > and it's written in C with a little assembly.


    Inlining means that a function declared as 'inline' (which has become
    an offical C feature only with C99 but was supported by many compilers
    before as an extension) will not be really created but instead the code
    for the function is placed everywhere where the function is called.
    Lets say you have an inlined function my_abs():

    inline double my_abs( double val )
    {
    return val >= 0 ? val : - val;
    }

    and you call it as

    x = my_abs( y );

    then the compiler won't create a call to the function but instead will
    replace it with the functions code, resulting in something similar to

    x = y >= 0 ? y : - y;

    This can increase execution speed a bit because the overhead for calling
    a function is eliminated.
    Regards, Jens
    --
    _ _____ _____
    | ||_ _||_ _| -berlin.de
    _ | | | | | |
    | |_| | | | | | http://www.physik.fu-berlin.de/~toerring
    \___/ens|_|homs|_|oerring
     
    -berlin.de, Oct 5, 2003
    #2
    1. Advertising

  3. Greetings.

    In article <>, Bill Cunningham wrote:
    > What is C inlinging? Or inlining. Does it have something to do with using
    > C and assembly language together? I know some of the linux kernel is
    > inlined and it's written in C with a little assembly.


    The term 'inlining' can have different meanings. In standard C, it refers
    to declaring a function with the 'inline' keyword, which is a suggestion to
    the compiler that it insert the function's code verbatim wherever it is
    called, rather than only producing the code for the function once and
    calling it as a subroutine. Obviously there's a time-space tradeoff
    involved.

    The meaning of 'inline' you refer to deals with inserting code from another
    programming language, such as SQL or assembly, into a C program. Support
    for this type of inlining is compiler-specific; ISO/ANSI C does not provide
    for a standard method. If you want to know how to inline assembly in C or
    have questions about the Linux kernel, you need to ask on a Linux- or
    compiler-specific newsgroup.

    Regards,
    Tristan

    --
    _
    _V.-o Tristan Miller [en,(fr,de,ia)] >< Space is limited
    / |`-' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-= <> In a haiku, so it's hard
    (7_\\ http://www.nothingisreal.com/ >< To finish what you
     
    Tristan Miller, Oct 5, 2003
    #3
  4. Bill Cunningham

    Malcolm Guest

    "Bill Cunningham" <> wrote in message
    > What is C inlinging? Or inlining. Does it have something to do with
    > using C and assembly language together? I know some of the linux
    > kernel is inlined and it's written in C with a little assembly.
    >

    Most compilers allow you to add assembly statements to C code, typically
    using "asm" as a keyword.
    Needless to say, the details are very platform-specific, and such code is
    not portable.
     
    Malcolm, Oct 5, 2003
    #4
  5. "Malcolm" <> wrote in message
    news:blq3p8$vrm$...
    >
    > "Bill Cunningham" <> wrote in message
    > > What is C inlinging? Or inlining. Does it have something to do with
    > > using C and assembly language together? I know some of the linux
    > > kernel is inlined and it's written in C with a little assembly.
    > >

    > Most compilers allow you to add assembly statements to C code, typically
    > using "asm" as a keyword.
    > Needless to say, the details are very platform-specific, and such code is
    > not portable.


    OTOH, inlining may have nothing to do with asm. The C99 keyword inline,
    supported by many pre-C99 compilers as a common extension, means basically
    that the function body is expanded whenever the function declared as
    inline is called. This saves a function call overhead and allows for
    better optimization, but tends to bloat the code if the inline function
    is used in more than one place.

    Sorry if this has been mentioned in the thread already, I have joined only
    now and have not seen any other reply than Malcolm's.
     
    Peter Pichler, Oct 29, 2003
    #5
    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. Matthew Lenz
    Replies:
    0
    Views:
    532
    Matthew Lenz
    Feb 22, 2005
  2. Ronald Fischer
    Replies:
    3
    Views:
    587
    Roedy Green
    Jul 20, 2004
  3. Alex
    Replies:
    6
    Views:
    427
  4. Aaron Fude

    Java and inlining

    Aaron Fude, Dec 17, 2004, in forum: Java
    Replies:
    4
    Views:
    378
    Aaron Fude
    Dec 18, 2004
  5. David Rubin
    Replies:
    8
    Views:
    501
    David Rubin
    Jan 15, 2004
Loading...

Share This Page