C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Drop same sequence of tokens for inline

From: Jonathan Wakely <cxx_at_[hidden]>
Date: Fri, 5 May 2023 08:29:15 +0100
On Fri, 5 May 2023 at 08:03, David Brown via Std-Proposals <
std-proposals_at_[hidden]> wrote:

>
> > Modern GCC considers that throwing code is unlikely, just as if you had a
> > [[likely]] attribute on that first if or __builtin_expected, so it moves
> the
> > else branch to a separate block. You can see it in action in
> > <https://gcc.godbolt.org/z/ns6Ph51Go>; note how there's a symbol with
> "[clone
> > .cold]" suffix (if you turn on directives, you'll see that it's even in
> an
> > entirely different section of the executable).
>
> This is a completely different concept from the "inline" keyword.
>
> Historically, the "inline" keyword was added to C and C++ as a compiler
> hint, in the days of weaker compilers. These days, compilers make their
> own decisions (influenced by compiler flags, pragmas, compiler-specific
> attributes, etc.) about code generation. The compiler will inline some
> or all of a function with a total disregard for the "inline" keyword.
> It will also happily outline code that happens to be within a function
> declared "inline".
>
> It is important to concentrate on the semantics of "inline" - what it
> actually means in the code. (It is also important to consider what it
> means to people reading the code.) Leave the code generation details to
> the compiler.
>

I agree, but G++ does actually use 'inline' as a hint that the function
should be inlined (IMHO this is unfortunate).

Received on 2023-05-05 07:29:30