tinycc-devel
[Top][All Lists]
Advanced

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

[Tinycc-devel] RE :Re: inline functions


From: Christian JULLIEN
Subject: [Tinycc-devel] RE :Re: inline functions
Date: Wed, 11 Dec 2013 09:28:07 +0100 (CET)


> Normally an inline must be locally defined ?

Makes sense.

NO! inline keyword is only a hint to the compiler that a function is supposed small enough to be inlined. It's perfectly legal for a compiler to ignore this hint if it thinks it's too complicated to inline this code.
C standard does not specify the minimal complexity to insure an inline function is actually inlined.

From function definition point of view, inlined keyword does not play a specific role for function visibility.

More precisely:

inline void f() { ... }
is like
void f() { .. }
and as an external visibility.

Even not commonly used a DEFINITION like

void f() { ... }
is in fact
extern void f() { ... }

Because extern is the default linkage either for a variable or a function. (extern int i = 100; is not a declaration but a legal definition)

It means that if you include this definition form 2 translation units you will have different results depending if inlined function has been inlined or not.

If you want to avoid problems when you define an inlined function in a .h is to declare this function static. This way, if compiler is not able to inline function, the two or more translation units using it will have their own static copy that will make linker happy.

Christian

reply via email to

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