This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: undefined errors for inline function
- From: Xi Ruoyao <ryxi at stu dot xidian dot edu dot cn>
- To: vijay nag <vijunag at gmail dot com>, "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Cc: ryxi at stu dot xidian dot edu dot cn
- Date: Mon, 30 Jan 2017 17:34:13 +0800
- Subject: Re: undefined errors for inline function
- Authentication-results: sourceware.org; auth=none
- References: <CAKhyrx8d3Ccs9tCBO+ESYZDC4VDdVFu8JtTV+ks0FgcbH9pfNA@mail.gmail.com>
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@stu.xidian.edu.cn>
School of Aerospace Science and Technology, Xidian University