Use of inline function in inline function - is it allowed?

Discussion in 'C Programming' started by TGOS, Feb 26, 2005.

  1. TGOS

    TGOS Guest

    Is it allowed and safe with most compiler, to use inline within an
    inline function?

    E.g.

    static inline void
    myFunc()
    {
    ...
    }


    static inline void
    myFunc2()
    {
    ...
    myFunc();
    ...
    }


    static inline void
    myFunc3()
    {
    ...
    myFunc();
    ...
    }


    And now I'm calling myFunc(), myFunc2() and myFunc3() at different
    occassions all over the rest of code. Is that legal?

    Because I had a strange bug in my program and after removing the inline
    of the three functions, the bug was gone. Coincident? A bug in the
    compiler? I don't know for sure.

    So I thought, lets first ask some experts if inlining in inlined
    functions is considered a safe operation.

    --
    TGOS
     
    TGOS, Feb 26, 2005
    #1
    1. Advertising

  2. TGOS

    -berlin.de Guest

    TGOS <> wrote:
    > Is it allowed and safe with most compiler, to use inline within an
    > inline function?


    If you define what you take to be "most" compilers it would be easier
    to answer;-) The C89 standard doesn't mention 'inline', but C99 now
    has it. That probably means that a lot of compilers already had
    'inline' and it therefor became included into the standard. But as
    long as the compiler is only C89 and not C99 compliant it don't need
    to have it. For such compilers you are going to need a line like

    #defined inline

    to make the compiler "overlook" it. But you will easily see if you
    need that because the compiler should complain loudly if it doesn't
    know what 'inline' is.

    > Because I had a strange bug in my program and after removing the inline
    > of the three functions, the bug was gone. Coincident? A bug in the
    > compiler? I don't know for sure.


    That may only be a side effect of using 'inline' - my first guess
    would be that you have some memory corrution in your program and,
    since the layout of the program might be quite different with in-
    lined functions, switching inlining on just exposes the bug.

    Regards, Jens
    --
    \ Jens Thoms Toerring ___ -berlin.de
    \__________________________ http://www.toerring.de
     
    -berlin.de, Feb 26, 2005
    #2
    1. Advertising

  3. "TGOS" <> wrote in message
    news:1109425568.decc7d5e22696623245feb600b2c888c@meganetnews2...
    >
    >
    > Is it allowed and safe with most compiler, to use inline within an
    > inline function?
    >
    > E.g.
    >
    > static inline void
    > myFunc()
    > {
    > ...
    > }
    >
    >
    > static inline void
    > myFunc2()
    > {
    > ...
    > myFunc();
    > ...
    > }
    >
    >
    > static inline void
    > myFunc3()
    > {
    > ...
    > myFunc();
    > ...
    > }
    >
    >
    > And now I'm calling myFunc(), myFunc2() and myFunc3() at different
    > occassions all over the rest of code. Is that legal?
    >
    > Because I had a strange bug in my program and after removing the inline
    > of the three functions, the bug was gone. Coincident? A bug in the
    > compiler? I don't know for sure.
    >
    > So I thought, lets first ask some experts if inlining in inlined
    > functions is considered a safe operation.
    >
    > --
    > TGOS


    Declaring a function as inline, should only change the calling convention
    used, as such anyplace you can call a function you should be able to call an
    inline function.

    I am not aware of any compilers that do allow one level, but not two.
    Unfortunately I am not aware of all the compilers out there.

    I'd say that if your compiler has a problem with it, dump it, and find a new
    compiler.
     
    DHOLLINGSWORTH2, Feb 27, 2005
    #3
  4. TGOS

    Kevin Bracey Guest

    In message <1109425568.decc7d5e22696623245feb600b2c888c@meganetnews2>
    TGOS <> wrote:

    >
    >
    > Is it allowed and safe with most compiler, to use inline within an
    > inline function?
    >
    > And now I'm calling myFunc(), myFunc2() and myFunc3() at different
    > occassions all over the rest of code. Is that legal?


    Absolutely. "inline" doesn't change the semantics of calls at all. Indeed, an
    inline function is allowed to call itself recursively.

    Exactly what the compiler does in these cases, and how efficient it is, are
    an implementation matter.

    > Because I had a strange bug in my program and after removing the inline
    > of the three functions, the bug was gone. Coincident? A bug in the
    > compiler? I don't know for sure.


    Sounds like a compiler bug. "inline" should not normally affect the
    observable behaviour. There might be some edge cases if you have different
    inline and out-of-line definitions (which is unusual but permitted).

    [ My responses refer to C99 - you may be using a pre-C99 compiler with its
    own inline semantics. ]

    --
    Kevin Bracey, Principal Software Engineer
    Tematic Ltd Tel: +44 (0) 1223 503464
    182-190 Newmarket Road Fax: +44 (0) 1728 727430
    Cambridge, CB5 8HE, United Kingdom WWW: http://www.tematic.com/
     
    Kevin Bracey, Feb 28, 2005
    #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. Nish
    Replies:
    4
    Views:
    494
    Thomas Stegen
    Oct 8, 2004
  2. Ajay
    Replies:
    5
    Views:
    393
    Pete Becker
    Apr 1, 2006
  3. Replies:
    7
    Views:
    443
  4. Stef Mientki
    Replies:
    4
    Views:
    243
    Terry Reedy
    Jul 30, 2008
  5. Iñaki Baz Castillo
    Replies:
    13
    Views:
    505
    Iñaki Baz Castillo
    May 1, 2011
Loading...

Share This Page