tinycc-devel
[Top][All Lists]
Advanced

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

[Tinycc-devel] c89 vs c99 inline functions


From: Андрей Аладьев
Subject: [Tinycc-devel] c89 vs c99 inline functions
Date: Fri, 17 Jan 2014 13:35:57 +0300

Hello. Do you plan to support -std=c99 switch?
I can show an example why it is important.


file test.h

inline int func()
{
return 0;
}

file test.c

#include "test.h"
extern inline int func();

file main.c

#include "test.h"
int main ()
{
return func();
}

gcc test.c -c -o test.o
gcc main.c -c -o main.o
gcc test.o main.o -o main

>> multiple definition of `func'

gcc -std=c99 test.c -c -o test.o
gcc -std=c99 main.c -c -o main.o
gcc test.o main.o -o main

>> ok


I can show why it is important to add "extern inline" of function in c99 standart:

gcc -std=c99 -O2 main.c -o main

>> ok

gcc -std=c99 -O0 main.c -o main

>> undefined reference to `func'

gcc -std=c99 -O0 test.c -c -o test.o
gcc -std=c99 -O0 main.c -c -o main.o
gcc test.o main.o -o main

>> ok

In "-O0" mode compiler can't inline functions, so you should have "extern inline" version of inline functions in object files.


Tcc works the same as gcc:

tcc test.c -c -o test.o
tcc main.c -c -o main.o
tcc test.o main.o -o main

>> main.o: error: 'func' defined twice

Thank you.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]