inline

Discussion in 'C Programming' started by Mark, Nov 3, 2011.

  1. Mark

    Mark Guest

    Hello

    is it required to have 'inline' keywoard before type in a function
    definition/declaration? For example, what is correct:

    inline int small_func(void)
    {
    /* do something */
    }

    or

    int inline small_func(void)
    {
    /* do something */
    }

    Also - is the same true for functions having static definition?

    Thanks.

    Mark
    Mark, Nov 3, 2011
    #1
    1. Advertising

  2. Mark

    Ben Pfaff Guest

    "Mark" <> writes:

    > is it required to have 'inline' keywoard before type in a function
    > definition/declaration? For example, what is correct:
    >
    > inline int small_func(void)
    > {
    > /* do something */
    > }
    >
    > or
    >
    > int inline small_func(void)
    > {
    > /* do something */
    > }


    Both are correct but the former is customary.

    > Also - is the same true for functions having static definition?


    Same answer.
    --
    char a[]="\n .CJacehknorstu";int putchar(int);int main(void){unsigned long b[]
    ={0x67dffdff,0x9aa9aa6a,0xa77ffda9,0x7da6aa6a,0xa67f6aaa,0xaa9aa9f6,0x11f6},*p
    =b,i=24;for(;p+=!*p;*p/=4)switch(0[p]&3)case 0:{return 0;for(p--;i--;i--)case+
    2:{i++;if(i)break;else default:continue;if(0)case 1:putchar(a[i&15]);break;}}}
    Ben Pfaff, Nov 3, 2011
    #2
    1. Advertising

  3. Mark

    Mark Guest

    "Ben Pfaff" <> wrote in message
    news:...
    >> is it required to have 'inline' keywoard before type in a function
    >> definition/declaration? For example, what is correct:
    >>
    >> inline int small_func(void)
    >> {
    >> /* do something */
    >> }
    >>
    >> or
    >>
    >> int inline small_func(void)
    >> {
    >> /* do something */
    >> }

    >
    > Both are correct but the former is customary.
    >
    >> Also - is the same true for functions having static definition?


    For the second case "gcc -std=c99 -pedantic -W -Wall" gives warning: 'inline'
    is not at beginning of declaration. Why does gcc care about the sequence if
    both representations are correct ?
    Thanks.

    Mark
    Mark, Nov 3, 2011
    #3
  4. Mark

    Ben Pfaff Guest

    "Mark" <> writes:

    > For the second case "gcc -std=c99 -pedantic -W -Wall" gives
    > warning: 'inline' is not at beginning of declaration. Why does
    > gcc care about the sequence if both representations are correct
    > ?


    It's customary to put 'inline' at the beginning. GCC is
    suggesting that you might have made a mistake. It's a warning,
    not an error, so you can ignore it or turn it off if you prefer
    to use an unusual ordering.
    --
    char a[]="\n .CJacehknorstu";int putchar(int);int main(void){unsigned long b[]
    ={0x67dffdff,0x9aa9aa6a,0xa77ffda9,0x7da6aa6a,0xa67f6aaa,0xaa9aa9f6,0x11f6},*p
    =b,i=24;for(;p+=!*p;*p/=4)switch(0[p]&3)case 0:{return 0;for(p--;i--;i--)case+
    2:{i++;if(i)break;else default:continue;if(0)case 1:putchar(a[i&15]);break;}}}
    Ben Pfaff, Nov 3, 2011
    #4
  5. Mark

    Kaz Kylheku Guest

    On 2011-11-03, Mark <> wrote:
    >
    > "Ben Pfaff" <> wrote in message
    > news:...
    >>> is it required to have 'inline' keywoard before type in a function
    >>> definition/declaration? For example, what is correct:
    >>>
    >>> inline int small_func(void)
    >>> {
    >>> /* do something */
    >>> }
    >>>
    >>> or
    >>>
    >>> int inline small_func(void)
    >>> {
    >>> /* do something */
    >>> }

    >>
    >> Both are correct but the former is customary.
    >>
    >>> Also - is the same true for functions having static definition?

    >
    > For the second case "gcc -std=c99 -pedantic -W -Wall" gives warning: 'inline'
    > is not at beginning of declaration. Why does gcc care about the sequence if
    > both representations are correct ?


    gcc doesn't provide warnings about only what is incorrect, but also
    stylistic warnings. This is also correct:

    (a && b || c)

    So is this

    while (x = 0) { ... }

    The above could be potential bugs, though.

    Furthermore, some of GCC's warnings also helps with portability issues. Inline
    functions were an extension in many C compilers for a long time. Maybe not all
    C compilers with an inline extension allowed the keyword to be in any position
    among the specifiers.

    This might be something that has been in GCC for some time. It's also issued
    for the GNU C dialect (that you get if you don't use -ansi or -std=c99).
    The minimal set of options that obtain this warning are:

    gcc -W foo.c

    By the way, I also tried the C++ front end (gcc 4.4.1) and see that it does
    not have such a warning. It's implemented in the C front end only.
    Kaz Kylheku, Nov 3, 2011
    #5
  6. "Mark" <> writes:
    > "Ben Pfaff" <> wrote in message
    > news:...
    >>> is it required to have 'inline' keywoard before type in a function
    >>> definition/declaration? For example, what is correct:
    >>>
    >>> inline int small_func(void)
    >>> {
    >>> /* do something */
    >>> }
    >>>
    >>> or
    >>>
    >>> int inline small_func(void)
    >>> {
    >>> /* do something */
    >>> }

    >>
    >> Both are correct but the former is customary.
    >>
    >>> Also - is the same true for functions having static definition?

    >
    > For the second case "gcc -std=c99 -pedantic -W -Wall" gives
    > warning: 'inline' is not at beginning of declaration. Why does
    > gcc care about the sequence if both representations are correct ?


    C99 6.11.5 says:

    The placement of a storage-class specifier other than at the
    beginning of the declaration specifiers in a declaration is an
    obsolescent feature.

    This doesn't apply to function declarations, but I would think that the
    placement of "inline" should be treated similarly.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
    Keith Thompson, Nov 3, 2011
    #6
    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. Abhi
    Replies:
    2
    Views:
    728
    E. Robert Tisdale
    Jul 3, 2003
  2. Alvin
    Replies:
    7
    Views:
    468
    E. Robert Tisdale
    May 6, 2005
  3. Replies:
    3
    Views:
    451
  4. Daniel Vallstrom
    Replies:
    2
    Views:
    1,834
    Kevin Bracey
    Nov 21, 2003
  5. Nish
    Replies:
    4
    Views:
    480
    Thomas Stegen
    Oct 8, 2004
Loading...

Share This Page