Is “inline” without “static” or “extern” ever useful in C99?

前端 未结 3 1139
清歌不尽
清歌不尽 2020-11-22 04:35

When I try to build this code

inline void f() {}

int main()
{
    f();
}

using the command line

gcc -std=c99 -o a a.c
         


        
3条回答
  •  天命终不由人
    2020-11-22 05:32

    Actually this excellent answer also answers your question, I think:

    What does extern inline do?

    The idea is that "inline" can be used in a header file, and then "extern inline" in a .c file. "extern inline" is just how you instruct the compiler which object file should contain the (externally visible) generated code.

    [update, to elaborate]

    I do not think there is any use for "inline" (without "static" or "extern") in a .c file. But in a header file it makes sense, and it requires a corresponding "extern inline" declaration in some .c file to actually generate the stand-alone code.

提交回复
热议问题