On Saturday, November 17, 2018 at 3:20:47 PM UTC-6, Alf P. Steinbach wrote:
> On 17.11.2018 21:58,
woodb...@gmail.com wrote:
> > I was until today laboring under the idea that I needed to
> > mark all non-template functions in header files as inline.
> > Then I read on reddit/learnprogramming:
> >
> > "Almost all templates and constexpr values are implicitly inline. Also any function defined inside a class."
>
> That's very wrong, pure disinformation.
>
> A function defined inside a class is implicitly `inline`, yes.
>
> However, a freestanding function template is not, and a `constexpr` is not.
Well, I have some freestanding function templates that aren't
marked as inline and neither gcc 8.2 or clang 7.0 say anything
about that. I'm not sure it's a problem.
>
> If you fully specialize a function template you don't get an `inline`
> function, unless you add the keyword `inline`. So you can easily run
> into multiple definition errors. It depends on what you do.
>
> If you take the address of a not explicitly inlined `constexpr` value in
> two different translation units, you get two different addresses. If you
> do that with an `inline` value you get the same address.
>
>
> > It's the last part about functions defined inside a class that
> > I didn't know or had forgotten. I've now updated my software:
> >
https://github.com/Ebenezer-group/onwards
> >
> > and tested that this is kosher with both gcc and clang. Removing
> > the superfluous inline keywords didn't make any difference to
> > the size of the text segments for gcc 8.2, but for clang 7.0 it
> > led to a bit smaller text segments.
> >
> > I'm encouraged by these events and ask for further review of my software.
>
> Hm, encouraged by disinformation that Seems To Work™.
>
I don't know if the author intended to muddy the waters.
At any rate, it was helpful to me in that some of it was
accurate.
Brian