Re: Issue with inline functions in dynamic libraries since GCC 5.1.0

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

 



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.



[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