Compiling error when -std=gnu99 and inline function is used

后端 未结 4 1359
轻奢々
轻奢々 2021-02-19 06:43

The following code:

#include 
inline int myfunc (int x) {
    return x+3;
}

int main () {

    printf(\"%d\", myfunc(2));
    return 0;
}
         


        
4条回答
  •  执念已碎
    2021-02-19 06:54

    This is the gnu_inline hiccup. Use -std=gnu99 -fgnu89-inline.

    For more information see Function Attributes (item gnu_inline).

    The relevant passage:

    In C, if the function is neither extern nor static, then the function is compiled as a standalone function, as well as being inlined where possible.

    This is how GCC traditionally handled functions declared inline. Since ISO C99 specifies a different semantics for inline, this function attribute is provided as a transition measure and as a useful feature in its own right. This attribute is available in GCC 4.1.3 and later. It is available if either of the preprocessor macros GNUC_GNU_INLINE or GNUC_STDC_INLINE are defined. See An Inline Function is As Fast As a Macro.

提交回复
热议问题