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

后端 未结 4 1361
轻奢々
轻奢々 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 07:15

    Apparently you need to specify that you are using and you want to adopt inline functions

    -fgnu89-inline
    

    The option -fgnu89-inline tells GCC to use the traditional GNU semantics for "inline" functions when in C99 mode. This option is accepted and ignored by GCC versions 4.1.3 up to but not including 4.3. In GCC versions 4.3 and later it changes the behavior of GCC in C99 mode. Using this option is roughly equivalent to adding the "gnu_inline" function attribute to all inline functions.

    The option -fno-gnu89-inline explicitly tells GCC to use the C99 semantics for "inline" when in C99 or gnu99 mode (i.e., it specifies the default behavior). This option was first supported in GCC 4.3. This option is not supported in C89 or gnu89 mode.

    The preprocessor macros __GNUC_GNU_INLINE__ and __GNUC_STDC_INLINE__ may be used to check which semantics are in effect for "inline" functions.

    Source: http://linux.die.net/man/1/gcc

    So to compile your code you need at least this:

    gcc source.c -std=gnu99 -fgnu89-inline
    

提交回复
热议问题