Re: undefined errors for inline function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2017-01-30 12:29 +0530, vijay nag wrote:
> Hello GCC,
> 
> I get linker error when I define/declare a function as inline in C
> file when -std=c99 flags are passed. 
> 
> cat linker.c
> 
> #include <stdio.h>
> 
> inline int Foo(long a, long b);
> inline int Foo(long a, long b) {
> }
> 
> int main() {
>   Foo(1, 3);
> }
> 
> Ubuntu:~]#gcc linker.c -std=c99
> /tmp/ccddb43a.o: In function `main':
> linker.c:(.text+0xf): undefined reference to `Foo'
> collect2: error: ld returned 1 exit status

The C99 Standard (ISO/IEC 9899:1999 6.7.4) says:

    Function specifiers shall be used *only* in the declaration of
    an identifier for a function.

In linker.c, we use the function specifier ``inline" in a
*definition*. It's illegal. But now GCC is not handling this properly.
In gcc/c/c-parser.c:

    Function specifiers (inline) are from C99, and are currently
    handled as storage class specifiers, as is __thread.

and:

    TODO: Distinguish between function specifiers and storage class
    specifiers, either here or in declspecs_add_scspec.
    
So currently GCC can not find this error. Some illegal code can be
compiled and linked successfully but others are complained by the
linker.

I hope the issue will be fixed soon.
-- 
Xi Ruoyao <ryxi@xxxxxxxxxxxxxxxxx>
School of Aerospace Science and Technology, Xidian University




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux