Path: csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c++
Subject: Re: Inline functions and locals
Date: Mon, 17 Jan 2022 15:29:57 -0800
Organization: A noiseless patient Spider
Lines: 46
Message-ID: <86a6furle2.fsf@linuxsc.com>
References:
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="d40b94b342f96ad99b493372f9984bf0"; logging-data="13427"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/gqsxE8yUy32h9BAHJWaMY6LwNosxUfW4="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:vvISzNFXTmiwq0liZWD/tdLUQ9c= sha1:SqzWKLgXeH1GHYRZEPD+BnMHk04=
Xref: csiph.com comp.lang.c++:82808
Andrey Tarasevich writes:
> On 1/16/2022 9:38 PM, Juha Nieminen wrote:
>
>> Andrey Tarasevich wrote:
>>
>>> As a historical note, it is true that keyword `inline` was
>>> originally introduced specifically to "suggest" inlining of
>>> function bodies at call sites. But it quickly became clear that
>>> it is useless and unnecessary in this role. As a consequence,
>>> its role was refocused to being a "ODR defeater" - a completely
>>> different purpose.
>>
>> And as a side note, the C standard also added support for
>> 'inline' functions, except that it's a different and very weird
>> version of it that to this day I still don't fully understand.
>> It's like an 'inline' that's *not* an "ODR defeater". (It's so
>> confusing that the vast, vast majority of C programmers just
>> write "static inline" to get around the confusing part.)
>
> Yes, you are right. `inline` is clearly an "ODR defeater" in C++,
> but in C... not so much.
>
> Firstly, `static inline` is a separate story. Most of the time
> static` is all that's needed. In a quality compiler `static
> inline` is always redundant. It is 100% equivalent to plain
> `static`. There's never any tangible reason to use `static` and
> `inline` together. [...]
In C++ I expect that's right. In C though there is a key
difference that may provide a reason to use 'inline'. In C
declaring or defining a function 'inline' can provide additional
guarantees beyond just using 'static'. In the semantics section
of 6.7.4 of the C standard, there is this excerpt:
Making a function an inline function suggests that calls to
the function be as fast as possible. The extent to which
such suggestions are effective is implementation-defined.
Note the second sentence. C implementations must document
what happens with 'inline', but there is no such requirement
for 'static'.
(I should add that I'm assuming that C++ does not impose a
similar requirement. I have not tried looking in the C++
standard to see if that is the case.)