Issue with inline functions in dynamic libraries since GCC 5.1.0

Jonathan Wakely jwakely.gcc@gmail.com
Mon Jun 29 17:44:00 GMT 2015


On 29 June 2015 at 17:17, Bas Mevissen wrote:
>
>
> On 06/27/2015 03:27 AM, Jonathan Wakely wrote:
>
>> GCC 5 defaults to C11, not C90, so 'inline' now has the C99 meaning,
>> not the non-standard GNU inline meaning. See
>> https://gcc.gnu.org/gcc-5/porting_to.html
>>
>
> Hi Jonathan,
>
> Thanks for your answer. From reading the text from the link, the changes
> to how inline is handled occurs very strange to me:
>
> "C99 inline: No externally visible function is generated. If the
> function is referenced in this TU, an external definition has to exist
> in another TU; same as GNU89 extern inline with no redefinition."
>
> So the *definition* of the inline function is then completely ignored?

No, if the compiler decides to inline the function then the definition is used.

> That means that something like
>
> inline void f1(void);
>
>
> int main(void)
> {
>         f1();
> }
>
> inline void f1(void)
> {
>
> }
>
> is not valid C99 nor C11.

Correct. The inline definition is only used if the compiler actually
performs function inlining (which only happens if optimisations are
enabled). So an external definition is also needed so it can be called
when the function isn't inlined.


> I'm curious about the reason(s) for the
> language to be defined this way.

It's simpler for compilers to support. If a compiler doesn't support
function inlining it can just ignore the inline definition and issue a
call to the external definition, which must be defined exactly once in
the program, so can be found by conventional linkers.



More information about the Gcc-help mailing list